mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-08-09 13:22:24 +03:00
0024757: DRAW: Move commands fixshape, tolerance, and similar to MODELING
Package SWDRAW has been moved to TKTopTest toolkit. Class SWDRAW_ToVRML has been moved to XSDRAWSTLVRML_ToVRML Removed unused classes: SWDRAW_ShapeBuild SWDRAW_ShapeConstruct XSDRAW_Shape Removed NSPApply command Test script update Removed xtrace command
This commit is contained in:
@@ -17,7 +17,7 @@ package XSDRAWSTLVRML
|
||||
|
||||
---Purpose:
|
||||
|
||||
uses Draw, MeshVS, StlMesh, TColStd, TCollection, Standard
|
||||
uses Draw, MeshVS, StlMesh, TColStd, TCollection, Standard, TopoDS
|
||||
|
||||
is
|
||||
|
||||
@@ -31,6 +31,9 @@ is
|
||||
class CoordsMap instantiates DataMap from TCollection
|
||||
( Integer from Standard, DataMapOfIntegerReal from TColStd, MapIntegerHasher from TColStd );
|
||||
|
||||
class ToVRML;
|
||||
---Purpose: A utility which writes a Shape to VRML format
|
||||
|
||||
InitCommands (theCommands : in out Interpretor from Draw);
|
||||
---Purpose : Inits commands for writing to STL and VRML formats
|
||||
|
||||
|
@@ -26,7 +26,6 @@
|
||||
#include <Quantity_HArray1OfColor.hxx>
|
||||
#include <StlAPI_Writer.hxx>
|
||||
#include <Draw_PluginMacro.hxx>
|
||||
#include <SWDRAW.hxx>
|
||||
#include <XSDRAW.hxx>
|
||||
#include <XSDRAWSTEP.hxx>
|
||||
#include <XSDRAWIGES.hxx>
|
||||
@@ -71,6 +70,8 @@
|
||||
#include <TColStd_Array1OfReal.hxx>
|
||||
#include <Bnd_Box.hxx>
|
||||
|
||||
#include <XSDRAWSTLVRML_ToVRML.hxx>
|
||||
|
||||
// avoid warnings on 'extern "C"' functions returning C++ classes
|
||||
#ifdef WNT
|
||||
#pragma warning(4:4190)
|
||||
@@ -979,6 +980,21 @@ static Standard_Integer mesh_edge_width( Draw_Interpretor& di,
|
||||
return 0;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : tovrml
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
static Standard_Integer tovrml(Draw_Interpretor& /*di*/, Standard_Integer n, const char** a)
|
||||
{
|
||||
if (n < 3) return 1;
|
||||
XSDRAWSTLVRML_ToVRML avrml;
|
||||
TopoDS_Shape sh = DBRep::Get (a[1]);
|
||||
const char* filename = a[2];
|
||||
if (!avrml.Write (sh,filename)) return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void XSDRAWSTLVRML::InitCommands (Draw_Interpretor& theCommands)
|
||||
@@ -987,6 +1003,7 @@ void XSDRAWSTLVRML::InitCommands (Draw_Interpretor& theCommands)
|
||||
//XSDRAW::LoadDraw(theCommands);
|
||||
|
||||
theCommands.Add ("writevrml", "shape file",__FILE__,writevrml,g);
|
||||
theCommands.Add ("tovrml", "shape file",__FILE__, tovrml, g);
|
||||
theCommands.Add ("writestl", "shape file [ascii/binary (0/1) : 1 by default] [InParallel (0/1) : 0 by default]",__FILE__,writestl,g);
|
||||
theCommands.Add ("readstl", "shape file",__FILE__,readstl,g);
|
||||
theCommands.Add ("loadvrml" , "shape file",__FILE__,loadvrml,g);
|
||||
@@ -1019,7 +1036,6 @@ void XSDRAWSTLVRML::Factory(Draw_Interpretor& theDI)
|
||||
XSDRAWIGES::InitFromBRep(theDI);
|
||||
XSDRAWSTEP::InitCommands(theDI);
|
||||
XSDRAWSTLVRML::InitCommands(theDI);
|
||||
SWDRAW::Init(theDI);
|
||||
XSDRAW::LoadDraw(theDI);
|
||||
#ifdef DEB
|
||||
theDI << "Draw Plugin : All TKXSDRAW commands are loaded" << "\n";
|
||||
|
80
src/XSDRAWSTLVRML/XSDRAWSTLVRML_ToVRML.cdl
Normal file
80
src/XSDRAWSTLVRML/XSDRAWSTLVRML_ToVRML.cdl
Normal file
@@ -0,0 +1,80 @@
|
||||
-- Created on: 1998-08-03
|
||||
-- Created by: Christian CAILLET
|
||||
-- Copyright (c) 1998-1999 Matra Datavision
|
||||
-- Copyright (c) 1999-2014 OPEN CASCADE SAS
|
||||
--
|
||||
-- This file is part of Open CASCADE Technology software library.
|
||||
--
|
||||
-- This library is free software; you can redistribute it and/or modify it under
|
||||
-- the terms of the GNU Lesser General Public License version 2.1 as published
|
||||
-- by the Free Software Foundation, with special exception defined in the file
|
||||
-- OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
|
||||
-- distribution for complete text of the license and disclaimer of any warranty.
|
||||
--
|
||||
-- Alternatively, this file may be used under the terms of Open CASCADE
|
||||
-- commercial license or contractual agreement.
|
||||
|
||||
class ToVRML from XSDRAWSTLVRML
|
||||
|
||||
---Purpose : Writes a Shape to a File in VRML Format
|
||||
|
||||
uses CString, OStream, AsciiString from TCollection, Shape from TopoDS
|
||||
|
||||
is
|
||||
|
||||
Create returns ToVRML;
|
||||
|
||||
EmissiveColorRed (me : in out) returns Real;
|
||||
---C++ : return &
|
||||
EmissiveColorGreen (me : in out) returns Real;
|
||||
---C++ : return &
|
||||
EmissiveColorBlue (me : in out) returns Real;
|
||||
---C++ : return &
|
||||
DiffuseColorRed (me : in out) returns Real;
|
||||
---C++ : return &
|
||||
DiffuseColorGreen (me : in out) returns Real;
|
||||
---C++ : return &
|
||||
DiffuseColorBlue (me : in out) returns Real;
|
||||
---C++ : return &
|
||||
Transparency (me : in out) returns Real;
|
||||
---C++ : return &
|
||||
AmbientIntensity (me : in out) returns Real;
|
||||
---C++ : return &
|
||||
SpecularColorRed (me : in out) returns Real;
|
||||
---C++ : return &
|
||||
SpecularColorGreen (me : in out) returns Real;
|
||||
---C++ : return &
|
||||
SpecularColorBlue (me : in out) returns Real;
|
||||
---C++ : return &
|
||||
Shininess (me : in out) returns Real;
|
||||
---C++ : return &
|
||||
Texture (me : in out) returns AsciiString;
|
||||
---C++ : return &
|
||||
CreaseAngle (me : in out) returns Real;
|
||||
---C++ : return &
|
||||
Deflection (me : in out) returns Real;
|
||||
---C++ : return &
|
||||
|
||||
|
||||
Write (me; shape : Shape from TopoDS; filename : CString) returns Boolean;
|
||||
---Purpose : conversion of a Shape into VRML format for 3d visualisation
|
||||
|
||||
fields
|
||||
|
||||
myEmissiveColorRed : Real; -- def 0.3
|
||||
myEmissiveColorGreen : Real; -- def 0.3
|
||||
myEmissiveColorBlue : Real; -- def 0.3
|
||||
myDiffuseColorRed : Real; -- def 0.3
|
||||
myDiffuseColorGreen : Real; -- def 0.3
|
||||
myDiffuseColorBlue : Real; -- def 0.5
|
||||
myTransparency : Real; -- def 0.0
|
||||
myAmbientIntensity : Real; -- def 0.3
|
||||
mySpecularColorRed : Real; -- def 0.7
|
||||
mySpecularColorGreen : Real; -- def 0.7
|
||||
mySpecularColorBlue : Real; -- def 0.8
|
||||
myShininess : Real; -- def 0.1
|
||||
myTexture : AsciiString; -- def " [] "
|
||||
myCreaseAngle : Real; -- def 1.57
|
||||
myDeflection : Real; -- def 0.005
|
||||
|
||||
end ToVRML;
|
188
src/XSDRAWSTLVRML/XSDRAWSTLVRML_ToVRML.cxx
Normal file
188
src/XSDRAWSTLVRML/XSDRAWSTLVRML_ToVRML.cxx
Normal file
@@ -0,0 +1,188 @@
|
||||
// Copyright (c) 1999-2014 OPEN CASCADE SAS
|
||||
//
|
||||
// This file is part of Open CASCADE Technology software library.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it under
|
||||
// the terms of the GNU Lesser General Public License version 2.1 as published
|
||||
// by the Free Software Foundation, with special exception defined in the file
|
||||
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
|
||||
// distribution for complete text of the license and disclaimer of any warranty.
|
||||
//
|
||||
// Alternatively, this file may be used under the terms of Open CASCADE
|
||||
// commercial license or contractual agreement.
|
||||
|
||||
#include <XSDRAWSTLVRML_ToVRML.ixx>
|
||||
|
||||
#include <Standard_Stream.hxx>
|
||||
#include <BRepMesh_FastDiscret.hxx>
|
||||
#include <BRepMesh_Triangle.hxx>
|
||||
#include <BRepMesh_Edge.hxx>
|
||||
#include <Bnd_Box.hxx>
|
||||
#include <BRepBndLib.hxx>
|
||||
|
||||
#include <gp_Pnt.hxx> //ied_modif_for_compil_Nov-20-1998
|
||||
|
||||
XSDRAWSTLVRML_ToVRML::XSDRAWSTLVRML_ToVRML ()
|
||||
{
|
||||
myEmissiveColorRed = 0.3;
|
||||
myEmissiveColorGreen = 0.3;
|
||||
myEmissiveColorBlue = 0.3;
|
||||
myDiffuseColorRed = 0.3;
|
||||
myDiffuseColorGreen = 0.3;
|
||||
myDiffuseColorBlue = 0.5;
|
||||
myTransparency = 0.0;
|
||||
myAmbientIntensity = 0.3;
|
||||
mySpecularColorRed = 0.7;
|
||||
mySpecularColorGreen = 0.7;
|
||||
mySpecularColorBlue = 0.8;
|
||||
myShininess = 0.1;
|
||||
myTexture = " [] " ;
|
||||
myCreaseAngle = 1.57;
|
||||
myDeflection = 0.005;
|
||||
}
|
||||
|
||||
Standard_Real& XSDRAWSTLVRML_ToVRML::EmissiveColorRed () { return myEmissiveColorRed ; }
|
||||
Standard_Real& XSDRAWSTLVRML_ToVRML::EmissiveColorGreen() { return myEmissiveColorGreen; }
|
||||
Standard_Real& XSDRAWSTLVRML_ToVRML::EmissiveColorBlue () { return myEmissiveColorBlue ; }
|
||||
Standard_Real& XSDRAWSTLVRML_ToVRML::DiffuseColorRed () { return myDiffuseColorRed ; }
|
||||
Standard_Real& XSDRAWSTLVRML_ToVRML::DiffuseColorGreen () { return myDiffuseColorGreen ; }
|
||||
Standard_Real& XSDRAWSTLVRML_ToVRML::DiffuseColorBlue () { return myDiffuseColorBlue ; }
|
||||
Standard_Real& XSDRAWSTLVRML_ToVRML::Transparency () { return myTransparency ; }
|
||||
Standard_Real& XSDRAWSTLVRML_ToVRML::AmbientIntensity () { return myAmbientIntensity ; }
|
||||
Standard_Real& XSDRAWSTLVRML_ToVRML::SpecularColorRed () { return mySpecularColorRed ; }
|
||||
Standard_Real& XSDRAWSTLVRML_ToVRML::SpecularColorGreen() { return mySpecularColorGreen; }
|
||||
Standard_Real& XSDRAWSTLVRML_ToVRML::SpecularColorBlue () { return mySpecularColorBlue ; }
|
||||
Standard_Real& XSDRAWSTLVRML_ToVRML::Shininess () { return myShininess ; }
|
||||
TCollection_AsciiString& XSDRAWSTLVRML_ToVRML::Texture () { return myTexture ; }
|
||||
Standard_Real& XSDRAWSTLVRML_ToVRML::CreaseAngle() { return myCreaseAngle; }
|
||||
Standard_Real& XSDRAWSTLVRML_ToVRML::Deflection () { return myDeflection ; }
|
||||
|
||||
//=======================================================================
|
||||
// function : ToVRML::Write
|
||||
// purpose : conversion of a Shape into VRML format for 3d visualisation
|
||||
//=======================================================================
|
||||
|
||||
Standard_Boolean XSDRAWSTLVRML_ToVRML::Write
|
||||
(const TopoDS_Shape& aShape, const Standard_CString filename) const
|
||||
{
|
||||
filebuf thefile;
|
||||
ostream TheFileOut(&thefile);
|
||||
|
||||
if (thefile.open(filename,ios::out))
|
||||
{
|
||||
|
||||
// Creates facets from the shape
|
||||
// Create (defle : Real from Standard;
|
||||
// shape : Shape from TopoDS;
|
||||
// angl : Real from Standard= 0.17;
|
||||
// withShare : Boolean from Standard=Standard_True;
|
||||
// inshape : Boolean from Standard=Standard_False;
|
||||
// relative : Boolean from Standard=Standard_False;
|
||||
// shapetrigu: Boolean from Standard=Standard_False)
|
||||
// returns mutable Discret from BRepMesh;
|
||||
Bnd_Box B;
|
||||
BRepBndLib::Add(aShape, B);
|
||||
|
||||
Handle(BRepMesh_FastDiscret) TheDiscret =
|
||||
new BRepMesh_FastDiscret(myDeflection,
|
||||
aShape,
|
||||
B,
|
||||
0.17,
|
||||
Standard_True,
|
||||
Standard_False,
|
||||
Standard_True,
|
||||
Standard_True);
|
||||
|
||||
Standard_Integer i,j;
|
||||
|
||||
// header of the VRML file
|
||||
TheFileOut << "#VRML V2.0 utf8" << endl;
|
||||
TheFileOut << "Group {" << endl;
|
||||
TheFileOut << " children [ " << endl;
|
||||
TheFileOut << " NavigationInfo {" << endl;
|
||||
TheFileOut << " type \"EXAMINE\" " << endl;
|
||||
TheFileOut << " }," << endl;
|
||||
TheFileOut << "Shape {" << endl;
|
||||
|
||||
TheFileOut << " appearance Appearance {" << endl;
|
||||
TheFileOut << " texture ImageTexture {" << endl;
|
||||
TheFileOut << " url " << myTexture.ToCString() << endl;
|
||||
TheFileOut << " }" << endl;
|
||||
TheFileOut << " material Material { " << endl;
|
||||
TheFileOut << " diffuseColor " << myDiffuseColorRed << " " << myDiffuseColorGreen << " " << myDiffuseColorBlue << " " << endl;
|
||||
TheFileOut << " emissiveColor " << myEmissiveColorRed << " "
|
||||
<< myEmissiveColorGreen << " " << myEmissiveColorBlue << " " << endl;
|
||||
TheFileOut << " transparency " << myTransparency << endl;
|
||||
TheFileOut << " ambientIntensity " << myAmbientIntensity << " " << endl;
|
||||
TheFileOut << " specularColor " << mySpecularColorRed << " " << mySpecularColorGreen << " " << mySpecularColorBlue << " " << endl;
|
||||
TheFileOut << " shininess " <<myShininess << " " << endl;
|
||||
TheFileOut << " }" << endl;
|
||||
TheFileOut << " }" << endl;
|
||||
|
||||
TheFileOut << " geometry IndexedFaceSet {" << endl;
|
||||
TheFileOut << " coord Coordinate {" << endl;
|
||||
TheFileOut << " point [" << endl;
|
||||
|
||||
// puts the coordinates of all the vertices using the order
|
||||
// given during the discretisation
|
||||
for (i=1;i<=TheDiscret->NbVertices();i++)
|
||||
{
|
||||
gp_Pnt TheVertex=TheDiscret->Pnt(i);
|
||||
TheFileOut << " "
|
||||
<< TheVertex.Coord().X() << " "
|
||||
<< TheVertex.Coord().Y() << " "
|
||||
<< TheVertex.Coord().Z() << "," << endl;
|
||||
}
|
||||
TheFileOut << " ]" << endl;
|
||||
TheFileOut << " }" << endl;
|
||||
|
||||
TheFileOut << " coordIndex [" << endl;
|
||||
|
||||
// retrieves all the triangles in order to draw the facets
|
||||
for (j=1; j <= TheDiscret->NbTriangles(); j++)
|
||||
{
|
||||
BRepMesh_Triangle TheTri=TheDiscret->Triangle(j);
|
||||
Standard_Integer e1,e2,e3,i1,i2,i3;
|
||||
Standard_Boolean b1,b2,b3;
|
||||
|
||||
TheTri.Edges(e1,e2,e3,b1,b2,b3);
|
||||
|
||||
if (b1)
|
||||
{
|
||||
i1 = TheDiscret->Edge(e1).FirstNode()-1;
|
||||
i2 = TheDiscret->Edge(e1).LastNode()-1;
|
||||
}
|
||||
else
|
||||
{
|
||||
i2 = TheDiscret->Edge(e1).FirstNode()-1;
|
||||
i1 = TheDiscret->Edge(e1).LastNode()-1;
|
||||
}
|
||||
|
||||
if (b2)
|
||||
{
|
||||
i3 = TheDiscret->Edge(e2).LastNode()-1;
|
||||
}
|
||||
else
|
||||
{
|
||||
i3 = TheDiscret->Edge(e2).FirstNode()-1;
|
||||
}
|
||||
|
||||
TheFileOut << " " << i1 << ", " << i2 << ", " << i3 << ", -1, " << endl;
|
||||
}
|
||||
|
||||
TheFileOut << " ]" << endl;
|
||||
TheFileOut << " solid FALSE" << endl; // it is not a closed solid
|
||||
TheFileOut << " creaseAngle " << myCreaseAngle << " " << endl; // for smooth shading
|
||||
TheFileOut << " }" << endl;
|
||||
TheFileOut << " }" << endl;
|
||||
TheFileOut << " ]" << endl;
|
||||
TheFileOut << "} " << endl;
|
||||
|
||||
}
|
||||
else return Standard_False; // failure when opening file
|
||||
|
||||
thefile.close();
|
||||
|
||||
return Standard_True;
|
||||
}
|
||||
|
Reference in New Issue
Block a user