1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-08-29 14:00:49 +03:00

Coding - Apply .clang-format formatting #286

Update empty method guards to new style with regex (see PR).
Used clang-format 18.1.8.
New actions to validate code formatting is added.
Update .clang-format with disabling of include sorting.
  It is temporary changes, then include will be sorted.
Apply formatting for /src and /tools folder.
The files with .hxx,.cxx,.lxx,.h,.pxx,.hpp,*.cpp extensions.
This commit is contained in:
dpasukhi
2025-01-25 20:15:22 +00:00
parent dbba6f1289
commit a5a7b3185b
14005 changed files with 1273539 additions and 1195567 deletions

View File

@@ -18,7 +18,10 @@
#include <TopoDS_Shape.hxx>
#include <VrmlAPI_Writer.hxx>
Standard_Boolean VrmlAPI::Write(const TopoDS_Shape& aShape, const Standard_CString aFileName, const Standard_Integer aVersion) {
Standard_Boolean VrmlAPI::Write(const TopoDS_Shape& aShape,
const Standard_CString aFileName,
const Standard_Integer aVersion)
{
VrmlAPI_Writer writer;
return writer.Write(aShape, aFileName, aVersion);
}

View File

@@ -23,20 +23,18 @@
#include <Standard_CString.hxx>
class TopoDS_Shape;
//! API for writing to VRML 1.0
class VrmlAPI
class VrmlAPI
{
public:
DEFINE_STANDARD_ALLOC
//! With help of this class user can change parameters of writing.
//! Converts the shape aShape to VRML format of the passed version and writes it
//! to the file identified by aFileName using default parameters.
Standard_EXPORT static Standard_Boolean Write (const TopoDS_Shape& aShape, const Standard_CString aFileName, const Standard_Integer aVersion = 2);
Standard_EXPORT static Standard_Boolean Write(const TopoDS_Shape& aShape,
const Standard_CString aFileName,
const Standard_Integer aVersion = 2);
};
#endif // _VrmlAPI_HeaderFile

View File

@@ -27,72 +27,84 @@ IMPLEMENT_STANDARD_RTTIEXT(VrmlAPI_CafReader, Standard_Transient)
namespace
{
//=======================================================================
// function : getVrmlErrorName
// purpose :
//=======================================================================
static TCollection_AsciiString getVrmlErrorName(VrmlData_ErrorStatus theStatus)
{
switch (theStatus)
{
case VrmlData_StatusOK: return "";
case VrmlData_EmptyData: return "EmptyData";
case VrmlData_UnrecoverableError: return "UnrecoverableError";
case VrmlData_GeneralError: return "GeneralError";
case VrmlData_EndOfFile: return "EndOfFile";
case VrmlData_NotVrmlFile: return "NotVrmlFile";
case VrmlData_CannotOpenFile: return "CannotOpenFile";
case VrmlData_VrmlFormatError: return "VrmlFormatError";
case VrmlData_NumericInputError: return "NumericInputError";
case VrmlData_IrrelevantNumber: return "IrrelevantNumber";
case VrmlData_BooleanInputError: return "BooleanInputError";
case VrmlData_StringInputError: return "StringInputError";
case VrmlData_NodeNameUnknown: return "NodeNameUnknown";
case VrmlData_NonPositiveSize: return "NonPositiveSize";
case VrmlData_ReadUnknownNode: return "ReadUnknownNode";
case VrmlData_NonSupportedFeature: return "NonSupportedFeature";
case VrmlData_OutputStreamUndefined: return "OutputStreamUndefined";
case VrmlData_NotImplemented: return "NotImplemented";
}
return "UNKNOWN";
}
//=================================================================================================
//=======================================================================
// function : performMeshSubshape
// purpose :
//=======================================================================
static void performMeshSubshape(RWMesh_NodeAttributeMap& theAttribMap,
const VrmlData_DataMapOfShapeAppearance& theShapeAppMap,
const TopoDS_Shape& theShape)
static TCollection_AsciiString getVrmlErrorName(VrmlData_ErrorStatus theStatus)
{
switch (theStatus)
{
Handle(VrmlData_Appearance) anAppearance;
if (theShapeAppMap.Find(theShape.TShape(), anAppearance))
{
if (!anAppearance.IsNull()
&& !anAppearance->Material().IsNull())
{
RWMesh_NodeAttributes aFaceAttribs;
theAttribMap.Find(theShape, aFaceAttribs);
aFaceAttribs.Style.SetColorSurf(anAppearance->Material()->DiffuseColor());
theAttribMap.Bind(theShape, aFaceAttribs);
}
}
for (TopoDS_Iterator aSubShapeIter(theShape, true, false); aSubShapeIter.More(); aSubShapeIter.Next())
{
performMeshSubshape(theAttribMap, theShapeAppMap, aSubShapeIter.Value());
}
case VrmlData_StatusOK:
return "";
case VrmlData_EmptyData:
return "EmptyData";
case VrmlData_UnrecoverableError:
return "UnrecoverableError";
case VrmlData_GeneralError:
return "GeneralError";
case VrmlData_EndOfFile:
return "EndOfFile";
case VrmlData_NotVrmlFile:
return "NotVrmlFile";
case VrmlData_CannotOpenFile:
return "CannotOpenFile";
case VrmlData_VrmlFormatError:
return "VrmlFormatError";
case VrmlData_NumericInputError:
return "NumericInputError";
case VrmlData_IrrelevantNumber:
return "IrrelevantNumber";
case VrmlData_BooleanInputError:
return "BooleanInputError";
case VrmlData_StringInputError:
return "StringInputError";
case VrmlData_NodeNameUnknown:
return "NodeNameUnknown";
case VrmlData_NonPositiveSize:
return "NonPositiveSize";
case VrmlData_ReadUnknownNode:
return "ReadUnknownNode";
case VrmlData_NonSupportedFeature:
return "NonSupportedFeature";
case VrmlData_OutputStreamUndefined:
return "OutputStreamUndefined";
case VrmlData_NotImplemented:
return "NotImplemented";
}
return "UNKNOWN";
}
//=======================================================================
// function : performMesh
// purpose :
//=======================================================================
bool VrmlAPI_CafReader::performMesh(std::istream& theStream,
//=================================================================================================
static void performMeshSubshape(RWMesh_NodeAttributeMap& theAttribMap,
const VrmlData_DataMapOfShapeAppearance& theShapeAppMap,
const TopoDS_Shape& theShape)
{
Handle(VrmlData_Appearance) anAppearance;
if (theShapeAppMap.Find(theShape.TShape(), anAppearance))
{
if (!anAppearance.IsNull() && !anAppearance->Material().IsNull())
{
RWMesh_NodeAttributes aFaceAttribs;
theAttribMap.Find(theShape, aFaceAttribs);
aFaceAttribs.Style.SetColorSurf(anAppearance->Material()->DiffuseColor());
theAttribMap.Bind(theShape, aFaceAttribs);
}
}
for (TopoDS_Iterator aSubShapeIter(theShape, true, false); aSubShapeIter.More();
aSubShapeIter.Next())
{
performMeshSubshape(theAttribMap, theShapeAppMap, aSubShapeIter.Value());
}
}
} // namespace
//=================================================================================================
bool VrmlAPI_CafReader::performMesh(std::istream& theStream,
const TCollection_AsciiString& theFile,
const Message_ProgressRange& theProgress,
const Standard_Boolean theToProbe)
const Message_ProgressRange& theProgress,
const Standard_Boolean theToProbe)
{
(void)theProgress;
if (!theStream.good())
@@ -117,14 +129,13 @@ bool VrmlAPI_CafReader::performMesh(std::istream& theStream,
aScene << theStream;
VrmlData_DataMapOfShapeAppearance aShapeAppMap;
TopoDS_Shape aShape = aScene.GetShape(aShapeAppMap);
TopoDS_Shape aShape = aScene.GetShape(aShapeAppMap);
if (!aShape.IsNull())
{
performMeshSubshape(myAttribMap, aShapeAppMap, aShape);
myRootShapes.Append(aShape);
}
if (aScene.Status() != VrmlData_StatusOK
|| aShape.IsNull())
if (aScene.Status() != VrmlData_StatusOK || aShape.IsNull())
{
Message::SendFail() << "Error in VrmlAPI_CafReader: " << getVrmlErrorName(aScene.Status())
<< "occurred at line " << aScene.GetLineError()

View File

@@ -22,18 +22,17 @@ class VrmlAPI_CafReader : public RWMesh_CafReader
DEFINE_STANDARD_RTTIEXT(VrmlAPI_CafReader, RWMesh_CafReader)
protected:
//! Read the mesh data from specified file.
//! @param theStream input stream
//! @param theFile path of additional files
//! @param theProgress progress indicator
//! @param theToProbe flag for probing file without complete reading. Not supported.
//! @return false when theToProbe is set to true or reading has completed with error.
Standard_EXPORT virtual Standard_Boolean performMesh (std::istream& theStream,
const TCollection_AsciiString& theFile,
const Message_ProgressRange& theProgress,
const Standard_Boolean theToProbe) Standard_OVERRIDE;
Standard_EXPORT virtual Standard_Boolean performMesh(std::istream& theStream,
const TCollection_AsciiString& theFile,
const Message_ProgressRange& theProgress,
const Standard_Boolean theToProbe)
Standard_OVERRIDE;
};
#endif // _VrmlAPI_Reader_HeaderFile

View File

@@ -27,9 +27,9 @@
//! wireframe. This is the default option.
enum VrmlAPI_RepresentationOfShape
{
VrmlAPI_ShadedRepresentation,
VrmlAPI_WireFrameRepresentation,
VrmlAPI_BothRepresentation
VrmlAPI_ShadedRepresentation,
VrmlAPI_WireFrameRepresentation,
VrmlAPI_BothRepresentation
};
#endif // _VrmlAPI_RepresentationOfShape_HeaderFile

View File

@@ -11,7 +11,6 @@
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#include <BRep_Tool.hxx>
#include <OSD_FileSystem.hxx>
#include <OSD_Path.hxx>
@@ -42,68 +41,86 @@
VrmlAPI_Writer::VrmlAPI_Writer()
{
myDrawer = new VrmlConverter_Drawer;
myDeflection = -1;
Handle(Quantity_HArray1OfColor) Col1 = new Quantity_HArray1OfColor (1, 1, Quantity_NOC_BLACK);
Handle(TColStd_HArray1OfReal) kik1 = new TColStd_HArray1OfReal(1,1,0.0);
Handle(TColStd_HArray1OfReal) kik2 = new TColStd_HArray1OfReal(1,1,0.1);
myFrontMaterial = new Vrml_Material(Col1,Col1, Col1, Col1, kik1, kik2);
myPointsMaterial = new Vrml_Material(Col1,Col1, Col1, Col1, kik1, kik2);
myUisoMaterial = new Vrml_Material(Col1,Col1, Col1, Col1, kik1, kik2);
myVisoMaterial = new Vrml_Material(Col1,Col1, Col1, Col1, kik1, kik2);
myLineMaterial = new Vrml_Material(Col1,Col1, Col1, Col1, kik1, kik2);
myWireMaterial = new Vrml_Material(Col1,Col1, Col1, Col1, kik1, kik2);
myFreeBoundsMaterial = new Vrml_Material(Col1,Col1, Col1, Col1, kik1, kik2);
myUnfreeBoundsMaterial = new Vrml_Material(Col1,Col1, Col1, Col1, kik1, kik2);
DX = 1;
DY = -1;
DZ = 1;
XUp = 0;
YUp = 0;
ZUp = 1;
Focus = 6;
myDrawer = new VrmlConverter_Drawer;
myDeflection = -1;
Handle(Quantity_HArray1OfColor) Col1 = new Quantity_HArray1OfColor(1, 1, Quantity_NOC_BLACK);
Handle(TColStd_HArray1OfReal) kik1 = new TColStd_HArray1OfReal(1, 1, 0.0);
Handle(TColStd_HArray1OfReal) kik2 = new TColStd_HArray1OfReal(1, 1, 0.1);
myFrontMaterial = new Vrml_Material(Col1, Col1, Col1, Col1, kik1, kik2);
myPointsMaterial = new Vrml_Material(Col1, Col1, Col1, Col1, kik1, kik2);
myUisoMaterial = new Vrml_Material(Col1, Col1, Col1, Col1, kik1, kik2);
myVisoMaterial = new Vrml_Material(Col1, Col1, Col1, Col1, kik1, kik2);
myLineMaterial = new Vrml_Material(Col1, Col1, Col1, Col1, kik1, kik2);
myWireMaterial = new Vrml_Material(Col1, Col1, Col1, Col1, kik1, kik2);
myFreeBoundsMaterial = new Vrml_Material(Col1, Col1, Col1, Col1, kik1, kik2);
myUnfreeBoundsMaterial = new Vrml_Material(Col1, Col1, Col1, Col1, kik1, kik2);
DX = 1;
DY = -1;
DZ = 1;
XUp = 0;
YUp = 0;
ZUp = 1;
Focus = 6;
ResetToDefaults();
}
void VrmlAPI_Writer::ResetToDefaults()
void VrmlAPI_Writer::ResetToDefaults()
{
myTransparency = 0.0;
myShininess = 0.1;
Handle(TColStd_HArray1OfReal) kik1 = new TColStd_HArray1OfReal(1,1,myTransparency);
Handle(TColStd_HArray1OfReal) kik2 = new TColStd_HArray1OfReal(1,1,myShininess);
Handle(Quantity_HArray1OfColor) Col = new Quantity_HArray1OfColor(1, 1, Quantity_NOC_BLACK);
myTransparency = 0.0;
myShininess = 0.1;
Handle(TColStd_HArray1OfReal) kik1 = new TColStd_HArray1OfReal(1, 1, myTransparency);
Handle(TColStd_HArray1OfReal) kik2 = new TColStd_HArray1OfReal(1, 1, myShininess);
Handle(Quantity_HArray1OfColor) Col = new Quantity_HArray1OfColor(1, 1, Quantity_NOC_BLACK);
//
myFrontMaterial->SetAmbientColor(Col); myFrontMaterial->SetTransparency(kik1);myFrontMaterial->SetShininess(kik2);
myPointsMaterial->SetAmbientColor(Col); myPointsMaterial->SetTransparency(kik1);myPointsMaterial->SetShininess(kik2);
myUisoMaterial->SetAmbientColor(Col); myUisoMaterial->SetTransparency(kik1);myUisoMaterial->SetShininess(kik2);
myVisoMaterial->SetAmbientColor(Col); myVisoMaterial->SetTransparency(kik1);myVisoMaterial->SetShininess(kik2);
myLineMaterial->SetAmbientColor(Col); myLineMaterial->SetTransparency(kik1);myLineMaterial->SetShininess(kik2);
myWireMaterial->SetAmbientColor(Col); myWireMaterial->SetTransparency(kik1); myWireMaterial->SetShininess(kik2);
myFreeBoundsMaterial->SetAmbientColor(Col); myFreeBoundsMaterial->SetTransparency(kik1);myFreeBoundsMaterial->SetShininess(kik2);
myUnfreeBoundsMaterial->SetAmbientColor(Col); myUnfreeBoundsMaterial->SetTransparency(kik1);myUnfreeBoundsMaterial->SetShininess(kik2);
myFrontMaterial->SetAmbientColor(Col);
myFrontMaterial->SetTransparency(kik1);
myFrontMaterial->SetShininess(kik2);
myPointsMaterial->SetAmbientColor(Col);
myPointsMaterial->SetTransparency(kik1);
myPointsMaterial->SetShininess(kik2);
myUisoMaterial->SetAmbientColor(Col);
myUisoMaterial->SetTransparency(kik1);
myUisoMaterial->SetShininess(kik2);
myVisoMaterial->SetAmbientColor(Col);
myVisoMaterial->SetTransparency(kik1);
myVisoMaterial->SetShininess(kik2);
myLineMaterial->SetAmbientColor(Col);
myLineMaterial->SetTransparency(kik1);
myLineMaterial->SetShininess(kik2);
myWireMaterial->SetAmbientColor(Col);
myWireMaterial->SetTransparency(kik1);
myWireMaterial->SetShininess(kik2);
myFreeBoundsMaterial->SetAmbientColor(Col);
myFreeBoundsMaterial->SetTransparency(kik1);
myFreeBoundsMaterial->SetShininess(kik2);
myUnfreeBoundsMaterial->SetAmbientColor(Col);
myUnfreeBoundsMaterial->SetTransparency(kik1);
myUnfreeBoundsMaterial->SetShininess(kik2);
//
//
Handle(Quantity_HArray1OfColor) Col2 = new Quantity_HArray1OfColor(1, 1, Quantity_Color (0.75, 0.75, 0.75, Quantity_TOC_sRGB));
Handle(Quantity_HArray1OfColor) Col3 = new Quantity_HArray1OfColor(1, 1, Quantity_Color (0.82, 0.79, 0.42, Quantity_TOC_sRGB));
Handle(Quantity_HArray1OfColor) Col2 =
new Quantity_HArray1OfColor(1, 1, Quantity_Color(0.75, 0.75, 0.75, Quantity_TOC_sRGB));
Handle(Quantity_HArray1OfColor) Col3 =
new Quantity_HArray1OfColor(1, 1, Quantity_Color(0.82, 0.79, 0.42, Quantity_TOC_sRGB));
myUisoMaterial->SetDiffuseColor(Col2);
myVisoMaterial->SetDiffuseColor(Col2);
myFreeBoundsMaterial->SetDiffuseColor(Col2);
myUnfreeBoundsMaterial->SetDiffuseColor(Col2);
//
// Handle(Quantity_HArray1OfColor) Col3 = new Quantity_HArray1OfColor(1,1);
// color.SetValues(Quantity_NOC_GOLD);
// Col3->SetValue(1,color);
// Handle(Quantity_HArray1OfColor) Col3 = new Quantity_HArray1OfColor(1,1);
// color.SetValues(Quantity_NOC_GOLD);
// Col3->SetValue(1,color);
myLineMaterial->SetDiffuseColor(Col2);
myWireMaterial->SetDiffuseColor(Col2);
//
// Handle(Quantity_HArray1OfColor) Col4 = new Quantity_HArray1OfColor(1,1);
// color.SetValues(Quantity_NOC_GOLD);
// Col4->SetValue(1,color);
// Handle(Quantity_HArray1OfColor) Col4 = new Quantity_HArray1OfColor(1,1);
// color.SetValues(Quantity_NOC_GOLD);
// Col4->SetValue(1,color);
myFrontMaterial->SetDiffuseColor(Col2);
myPointsMaterial->SetDiffuseColor(Col2);
//
myUisoMaterial->SetSpecularColor(Col3);
myVisoMaterial->SetSpecularColor(Col3);
myFreeBoundsMaterial->SetSpecularColor(Col3);
@@ -112,61 +129,73 @@ void VrmlAPI_Writer::ResetToDefaults()
myWireMaterial->SetSpecularColor(Col3);
myFrontMaterial->SetSpecularColor(Col3);
myPointsMaterial->SetSpecularColor(Col3);
myRepresentation = VrmlAPI_BothRepresentation;
}
Handle(VrmlConverter_Drawer) VrmlAPI_Writer::Drawer() const
{
return myDrawer;
}
void VrmlAPI_Writer::SetDeflection(const Standard_Real aDef)
{
myDeflection = aDef;
if (myDeflection > 0) {
if (myDeflection > 0)
{
myDrawer->SetMaximalChordialDeviation(myDeflection);
myDrawer->SetTypeOfDeflection(Aspect_TOD_ABSOLUTE);
}
else myDrawer->SetTypeOfDeflection(Aspect_TOD_RELATIVE);
else
myDrawer->SetTypeOfDeflection(Aspect_TOD_RELATIVE);
}
void VrmlAPI_Writer::SetRepresentation(const VrmlAPI_RepresentationOfShape aRep)
{
myRepresentation = aRep;
}
void VrmlAPI_Writer::SetTransparencyToMaterial(Handle(Vrml_Material)& aMaterial,const Standard_Real aTransparency)
void VrmlAPI_Writer::SetTransparencyToMaterial(Handle(Vrml_Material)& aMaterial,
const Standard_Real aTransparency)
{
Handle(TColStd_HArray1OfReal) t = new TColStd_HArray1OfReal(1,1,aTransparency);
Handle(TColStd_HArray1OfReal) t = new TColStd_HArray1OfReal(1, 1, aTransparency);
aMaterial->SetTransparency(t);
}
void VrmlAPI_Writer::SetShininessToMaterial(Handle(Vrml_Material)& aMaterial,const Standard_Real aShininess)
{
Handle(TColStd_HArray1OfReal) s = new TColStd_HArray1OfReal(1,1,aShininess);
void VrmlAPI_Writer::SetShininessToMaterial(Handle(Vrml_Material)& aMaterial,
const Standard_Real aShininess)
{
Handle(TColStd_HArray1OfReal) s = new TColStd_HArray1OfReal(1, 1, aShininess);
aMaterial->SetShininess(s);
}
void VrmlAPI_Writer::SetAmbientColorToMaterial(Handle(Vrml_Material)& aMaterial,const Handle(Quantity_HArray1OfColor)& Color)
void VrmlAPI_Writer::SetAmbientColorToMaterial(Handle(Vrml_Material)& aMaterial,
const Handle(Quantity_HArray1OfColor)& Color)
{
aMaterial->SetAmbientColor(Color);
}
void VrmlAPI_Writer::SetDiffuseColorToMaterial(Handle(Vrml_Material)& aMaterial,const Handle(Quantity_HArray1OfColor)& Color)
void VrmlAPI_Writer::SetDiffuseColorToMaterial(Handle(Vrml_Material)& aMaterial,
const Handle(Quantity_HArray1OfColor)& Color)
{
aMaterial->SetDiffuseColor(Color);
}
void VrmlAPI_Writer::SetSpecularColorToMaterial(Handle(Vrml_Material)& aMaterial,const Handle(Quantity_HArray1OfColor)& Color)
void VrmlAPI_Writer::SetSpecularColorToMaterial(Handle(Vrml_Material)& aMaterial,
const Handle(Quantity_HArray1OfColor)& Color)
{
aMaterial->SetSpecularColor(Color);
}
void VrmlAPI_Writer::SetEmissiveColorToMaterial(Handle(Vrml_Material)& aMaterial,const Handle(Quantity_HArray1OfColor)& Color)
void VrmlAPI_Writer::SetEmissiveColorToMaterial(Handle(Vrml_Material)& aMaterial,
const Handle(Quantity_HArray1OfColor)& Color)
{
aMaterial->SetEmissiveColor(Color);
}
VrmlAPI_RepresentationOfShape VrmlAPI_Writer::GetRepresentation() const
{
return myRepresentation;
return myRepresentation;
}
Handle(Vrml_Material) VrmlAPI_Writer::GetFrontMaterial() const
@@ -209,82 +238,86 @@ Handle(Vrml_Material) VrmlAPI_Writer::GetUnfreeBoundsMaterial() const
return myUnfreeBoundsMaterial;
}
Standard_Boolean VrmlAPI_Writer::Write(const TopoDS_Shape& aShape,const Standard_CString aFile, const Standard_Integer aVersion) const
Standard_Boolean VrmlAPI_Writer::Write(const TopoDS_Shape& aShape,
const Standard_CString aFile,
const Standard_Integer aVersion) const
{
if (aVersion == 1)
return write_v1 (aShape, aFile);
return write_v1(aShape, aFile);
else if (aVersion == 2)
return write_v2 (aShape, aFile);
return write_v2(aShape, aFile);
return Standard_False;
}
Standard_Boolean VrmlAPI_Writer::write_v1(const TopoDS_Shape& aShape,const Standard_CString aFile) const
Standard_Boolean VrmlAPI_Writer::write_v1(const TopoDS_Shape& aShape,
const Standard_CString aFile) const
{
OSD_Path thePath(aFile);
TCollection_AsciiString theFile;thePath.SystemName(theFile);
OSD_Path thePath(aFile);
TCollection_AsciiString theFile;
thePath.SystemName(theFile);
const Handle(OSD_FileSystem)& aFileSystem = OSD_FileSystem::DefaultFileSystem();
std::shared_ptr<std::ostream> anOutFile = aFileSystem->OpenOStream (theFile, std::ios::out | std::ios::binary);
std::shared_ptr<std::ostream> anOutFile =
aFileSystem->OpenOStream(theFile, std::ios::out | std::ios::binary);
if (anOutFile.get() == NULL)
{
return Standard_False;
}
Handle(VrmlConverter_IsoAspect) ia = new VrmlConverter_IsoAspect; // UIso
Handle(VrmlConverter_IsoAspect) ia1 = new VrmlConverter_IsoAspect; //VIso
Handle(VrmlConverter_IsoAspect) ia = new VrmlConverter_IsoAspect; // UIso
Handle(VrmlConverter_IsoAspect) ia1 = new VrmlConverter_IsoAspect; // VIso
ia->SetMaterial(myUisoMaterial);
ia->SetHasMaterial(Standard_True);
myDrawer->SetUIsoAspect(ia);
ia1->SetMaterial(myVisoMaterial);
ia1->SetHasMaterial(Standard_True);
myDrawer->SetVIsoAspect(ia1);
// default Number of iso lines is 10
//---- Definition of LineAspect (default - without own material)
// default Number of iso lines is 10
//---- Definition of LineAspect (default - without own material)
Handle(VrmlConverter_LineAspect) la = new VrmlConverter_LineAspect;
la->SetMaterial(myLineMaterial);
la->SetHasMaterial(Standard_True);
myDrawer->SetLineAspect(la);
//---- Definition of Wire (without any neighbour)
//---- Definition of Wire (without any neighbour)
Handle(VrmlConverter_LineAspect) lw = new VrmlConverter_LineAspect;
lw->SetMaterial(myWireMaterial);
lw->SetHasMaterial(Standard_True);
myDrawer->SetWireAspect(lw);
//---- Definition of Free boundaries
//---- Definition of Free boundaries
Handle(VrmlConverter_LineAspect) lf = new VrmlConverter_LineAspect;
lf->SetMaterial(myFreeBoundsMaterial);
lf->SetHasMaterial(Standard_True);
myDrawer->SetFreeBoundaryAspect(lf);
//---- Definition of Unfree boundaries
//---- Definition of Unfree boundaries
Handle(VrmlConverter_LineAspect) lun = new VrmlConverter_LineAspect;
lun->SetMaterial(myUnfreeBoundsMaterial);
lun->SetHasMaterial(Standard_True);
myDrawer->SetUnFreeBoundaryAspect(lun);
//---- Definition of Points (default - without own material)
//---- Definition of Points (default - without own material)
Handle(VrmlConverter_PointAspect) pa = new VrmlConverter_PointAspect;
pa->SetMaterial(myPointsMaterial);
pa->SetHasMaterial(Standard_True);
myDrawer->SetPointAspect(pa);
//-----------------------------------------
//-----------------------------------------
Handle(VrmlConverter_ShadingAspect) sa = new VrmlConverter_ShadingAspect;
sa->SetFrontMaterial(myFrontMaterial);
sa->SetHasMaterial(Standard_True);
Vrml_ShapeHints sh;
Vrml_ShapeHints sh;
sa->SetShapeHints(sh);
myDrawer->SetShadingAspect(sa);
//-------- Shape --------------------------
TopTools_Array1OfShape Shapes(1,1);
Shapes.SetValue(1,aShape);
//-------- Shape --------------------------
TopTools_Array1OfShape Shapes(1, 1);
Shapes.SetValue(1, aShape);
// Check shape tesselation
TopExp_Explorer anExp (aShape, TopAbs_FACE);
TopLoc_Location aLoc;
TopExp_Explorer anExp(aShape, TopAbs_FACE);
TopLoc_Location aLoc;
Standard_Boolean hasTriangles = Standard_False;
for (; anExp.More(); anExp.Next())
{
const TopoDS_Face& aFace = TopoDS::Face (anExp.Current());
if (!aFace.IsNull())
const TopoDS_Face& aFace = TopoDS::Face(anExp.Current());
if (!aFace.IsNull())
{
Handle(Poly_Triangulation) aTri =
BRep_Tool::Triangulation (aFace, aLoc);
Handle(Poly_Triangulation) aTri = BRep_Tool::Triangulation(aFace, aLoc);
if (!aTri.IsNull())
{
@@ -294,81 +327,84 @@ Standard_Boolean VrmlAPI_Writer::write_v1(const TopoDS_Shape& aShape,const Stand
}
}
//=========================================
//---- Definition of data for Projector
//=========================================
//=========================================
//---- Definition of data for Projector
//=========================================
VrmlConverter_TypeOfLight Light = VrmlConverter_NoLight;
VrmlConverter_TypeOfCamera Camera = VrmlConverter_PerspectiveCamera;
Handle(VrmlConverter_Projector) projector = new VrmlConverter_Projector (Shapes,
Focus,
DX, DY, DZ,
XUp, YUp, ZUp,
Camera,
Light);
Vrml::VrmlHeaderWriter (*anOutFile);
VrmlConverter_TypeOfLight Light = VrmlConverter_NoLight;
VrmlConverter_TypeOfCamera Camera = VrmlConverter_PerspectiveCamera;
Handle(VrmlConverter_Projector) projector =
new VrmlConverter_Projector(Shapes, Focus, DX, DY, DZ, XUp, YUp, ZUp, Camera, Light);
Vrml::VrmlHeaderWriter(*anOutFile);
if (myRepresentation == VrmlAPI_BothRepresentation)
Vrml::CommentWriter(" This file contents both Shaded and Wire Frame representation of selected Shape ", *anOutFile);
Vrml::CommentWriter(
" This file contents both Shaded and Wire Frame representation of selected Shape ",
*anOutFile);
if (myRepresentation == VrmlAPI_ShadedRepresentation)
Vrml::CommentWriter(" This file contents only Shaded representation of selected Shape ", *anOutFile);
Vrml::CommentWriter(" This file contents only Shaded representation of selected Shape ",
*anOutFile);
if (myRepresentation == VrmlAPI_WireFrameRepresentation)
Vrml::CommentWriter(" This file contents only Wire Frame representation of selected Shape ", *anOutFile);
Vrml::CommentWriter(" This file contents only Wire Frame representation of selected Shape ",
*anOutFile);
Vrml_Separator S1;
S1.Print (*anOutFile);
projector->Add (*anOutFile);
Light = VrmlConverter_DirectionLight;
S1.Print(*anOutFile);
projector->Add(*anOutFile);
Light = VrmlConverter_DirectionLight;
Camera = VrmlConverter_OrthographicCamera;
Handle(VrmlConverter_Projector) projector1 = new VrmlConverter_Projector (Shapes,
Focus,
DX, DY, DZ,
XUp, YUp, ZUp,
Camera,
Light);
projector1->Add (*anOutFile);
Handle(VrmlConverter_Projector) projector1 =
new VrmlConverter_Projector(Shapes, Focus, DX, DY, DZ, XUp, YUp, ZUp, Camera, Light);
projector1->Add(*anOutFile);
Vrml_Separator S2;
S2.Print (*anOutFile);
if ( (myRepresentation == VrmlAPI_ShadedRepresentation || myRepresentation == VrmlAPI_BothRepresentation) && hasTriangles)
{
Vrml_Group Group1;
Group1.Print (*anOutFile);
Vrml_Instancing I2 ("Shaded representation of shape");
I2.DEF (*anOutFile);
VrmlConverter_ShadedShape::Add (*anOutFile,aShape,myDrawer);
Group1.Print (*anOutFile);
}
if (myRepresentation == VrmlAPI_WireFrameRepresentation || myRepresentation == VrmlAPI_BothRepresentation)
{
Vrml_Group Group2;
Group2.Print (*anOutFile);
Vrml_Instancing I3 ("Wire Frame representation of shape");
I3.DEF (*anOutFile);
VrmlConverter_WFDeflectionShape::Add (*anOutFile,aShape,myDrawer);
Group2.Print (*anOutFile);
}
S2.Print (*anOutFile);
S1.Print (*anOutFile);
S2.Print(*anOutFile);
if ((myRepresentation == VrmlAPI_ShadedRepresentation
|| myRepresentation == VrmlAPI_BothRepresentation)
&& hasTriangles)
{
Vrml_Group Group1;
Group1.Print(*anOutFile);
Vrml_Instancing I2("Shaded representation of shape");
I2.DEF(*anOutFile);
VrmlConverter_ShadedShape::Add(*anOutFile, aShape, myDrawer);
Group1.Print(*anOutFile);
}
if (myRepresentation == VrmlAPI_WireFrameRepresentation
|| myRepresentation == VrmlAPI_BothRepresentation)
{
Vrml_Group Group2;
Group2.Print(*anOutFile);
Vrml_Instancing I3("Wire Frame representation of shape");
I3.DEF(*anOutFile);
VrmlConverter_WFDeflectionShape::Add(*anOutFile, aShape, myDrawer);
Group2.Print(*anOutFile);
}
S2.Print(*anOutFile);
S1.Print(*anOutFile);
anOutFile->flush();
return anOutFile->good();
}
Standard_Boolean VrmlAPI_Writer::write_v2(const TopoDS_Shape& aShape,const Standard_CString aFile) const
Standard_Boolean VrmlAPI_Writer::write_v2(const TopoDS_Shape& aShape,
const Standard_CString aFile) const
{
Standard_Boolean anExtFace = Standard_False;
if(myRepresentation == VrmlAPI_ShadedRepresentation || myRepresentation == VrmlAPI_BothRepresentation)
if (myRepresentation == VrmlAPI_ShadedRepresentation
|| myRepresentation == VrmlAPI_BothRepresentation)
anExtFace = Standard_True;
Standard_Boolean anExtEdge = Standard_False;
if(myRepresentation == VrmlAPI_WireFrameRepresentation || myRepresentation == VrmlAPI_BothRepresentation)
if (myRepresentation == VrmlAPI_WireFrameRepresentation
|| myRepresentation == VrmlAPI_BothRepresentation)
anExtEdge = Standard_True;
VrmlData_Scene aScene;
VrmlData_Scene aScene;
VrmlData_ShapeConvert aConv(aScene);
aConv.AddShape(aShape);
aConv.Convert(anExtFace, anExtEdge);
const Handle(OSD_FileSystem)& aFileSystem = OSD_FileSystem::DefaultFileSystem();
std::shared_ptr<std::ostream> anOutStream = aFileSystem->OpenOStream (aFile, std::ios::out | std::ios::binary);
std::shared_ptr<std::ostream> anOutStream =
aFileSystem->OpenOStream(aFile, std::ios::out | std::ios::binary);
if (anOutStream.get() != NULL)
{
*anOutStream << aScene;
@@ -379,21 +415,19 @@ Standard_Boolean VrmlAPI_Writer::write_v2(const TopoDS_Shape& aShape,const Stand
return Standard_False;
}
//=======================================================================
//function : WriteDoc
//purpose :
//=======================================================================
Standard_Boolean VrmlAPI_Writer::WriteDoc(
const Handle(TDocStd_Document) &theDoc,
const Standard_CString theFile,
const Standard_Real theScale) const
//=================================================================================================
Standard_Boolean VrmlAPI_Writer::WriteDoc(const Handle(TDocStd_Document)& theDoc,
const Standard_CString theFile,
const Standard_Real theScale) const
{
VrmlData_Scene aScene;
VrmlData_Scene aScene;
VrmlData_ShapeConvert aConv(aScene, theScale);
aConv.ConvertDocument(theDoc);
const Handle(OSD_FileSystem)& aFileSystem = OSD_FileSystem::DefaultFileSystem();
std::shared_ptr<std::ostream> anOutStream = aFileSystem->OpenOStream (theFile, std::ios::out | std::ios::binary);
std::shared_ptr<std::ostream> anOutStream =
aFileSystem->OpenOStream(theFile, std::ios::out | std::ios::binary);
if (anOutStream.get() != NULL)
{
*anOutStream << aScene;
@@ -403,4 +437,3 @@ Standard_Boolean VrmlAPI_Writer::WriteDoc(
anOutStream.reset();
return Standard_False;
}

View File

@@ -30,124 +30,126 @@ class Vrml_Material;
class TopoDS_Shape;
class TDocStd_Document;
//! Creates and writes VRML files from Open
//! CASCADE shapes. A VRML file can be written to
//! an existing VRML file or to a new one.
class VrmlAPI_Writer
class VrmlAPI_Writer
{
public:
DEFINE_STANDARD_ALLOC
//! Creates a writer object with default parameters.
Standard_EXPORT VrmlAPI_Writer();
//! Resets all parameters (representation, deflection)
//! to their default values..
Standard_EXPORT void ResetToDefaults();
//! Returns drawer object
Standard_EXPORT Handle(VrmlConverter_Drawer) Drawer() const;
//! Sets the deflection aDef of
//! the mesh algorithm which is used to compute the shaded
//! representation of the translated shape. The default
//! value is -1. When the deflection value is less than
//! 0, the deflection is calculated from the relative
//! size of the shaped.
Standard_EXPORT void SetDeflection (const Standard_Real aDef);
Standard_EXPORT void SetDeflection(const Standard_Real aDef);
//! Sets the representation of the
//! shape aRep which is written to the VRML file. The three options are :
//! - shaded
//! - wireframe
//! - both shaded and wireframe (default)
//! defined through the VrmlAPI_RepresentationOfShape enumeration.
Standard_EXPORT void SetRepresentation (const VrmlAPI_RepresentationOfShape aRep);
Standard_EXPORT void SetRepresentation(const VrmlAPI_RepresentationOfShape aRep);
//! Set transparency to given material
Standard_EXPORT void SetTransparencyToMaterial (Handle(Vrml_Material)& aMaterial, const Standard_Real aTransparency);
Standard_EXPORT void SetShininessToMaterial (Handle(Vrml_Material)& aMaterial, const Standard_Real aShininess);
Standard_EXPORT void SetAmbientColorToMaterial (Handle(Vrml_Material)& aMaterial, const Handle(Quantity_HArray1OfColor)& Color);
Standard_EXPORT void SetDiffuseColorToMaterial (Handle(Vrml_Material)& aMaterial, const Handle(Quantity_HArray1OfColor)& Color);
Standard_EXPORT void SetSpecularColorToMaterial (Handle(Vrml_Material)& aMaterial, const Handle(Quantity_HArray1OfColor)& Color);
Standard_EXPORT void SetEmissiveColorToMaterial (Handle(Vrml_Material)& aMaterial, const Handle(Quantity_HArray1OfColor)& Color);
Standard_EXPORT void SetTransparencyToMaterial(Handle(Vrml_Material)& aMaterial,
const Standard_Real aTransparency);
Standard_EXPORT void SetShininessToMaterial(Handle(Vrml_Material)& aMaterial,
const Standard_Real aShininess);
Standard_EXPORT void SetAmbientColorToMaterial(Handle(Vrml_Material)& aMaterial,
const Handle(Quantity_HArray1OfColor)& Color);
Standard_EXPORT void SetDiffuseColorToMaterial(Handle(Vrml_Material)& aMaterial,
const Handle(Quantity_HArray1OfColor)& Color);
Standard_EXPORT void SetSpecularColorToMaterial(Handle(Vrml_Material)& aMaterial,
const Handle(Quantity_HArray1OfColor)& Color);
Standard_EXPORT void SetEmissiveColorToMaterial(Handle(Vrml_Material)& aMaterial,
const Handle(Quantity_HArray1OfColor)& Color);
//! Returns the representation of the shape which is
//! written to the VRML file. Types of representation are set through the
//! VrmlAPI_RepresentationOfShape enumeration.
Standard_EXPORT VrmlAPI_RepresentationOfShape GetRepresentation() const;
Standard_EXPORT Handle(Vrml_Material) GetFrontMaterial() const;
Standard_EXPORT Handle(Vrml_Material) GetPointsMaterial() const;
Standard_EXPORT Handle(Vrml_Material) GetUisoMaterial() const;
Standard_EXPORT Handle(Vrml_Material) GetVisoMaterial() const;
Standard_EXPORT Handle(Vrml_Material) GetLineMaterial() const;
Standard_EXPORT Handle(Vrml_Material) GetWireMaterial() const;
Standard_EXPORT Handle(Vrml_Material) GetFreeBoundsMaterial() const;
Standard_EXPORT Handle(Vrml_Material) GetUnfreeBoundsMaterial() const;
//! Converts the shape aShape to
//! VRML format of the passed version and writes it to the file identified by aFile.
Standard_EXPORT Standard_Boolean Write (const TopoDS_Shape& aShape, const Standard_CString aFile,
const Standard_Integer aVersion = 2) const;
Standard_EXPORT Standard_Boolean Write(const TopoDS_Shape& aShape,
const Standard_CString aFile,
const Standard_Integer aVersion = 2) const;
//! Converts the document to VRML format of the passed version
//! and writes it to the file identified by aFile.
Standard_EXPORT Standard_Boolean WriteDoc(
const Handle(TDocStd_Document) &theDoc,
const Standard_CString theFile,
const Standard_Real theScale) const;
Standard_EXPORT Standard_Boolean WriteDoc(const Handle(TDocStd_Document)& theDoc,
const Standard_CString theFile,
const Standard_Real theScale) const;
protected:
//! Converts the shape aShape to VRML format of version 1.0 and writes it
//! to the file identified by aFileName using default parameters.
Standard_EXPORT Standard_Boolean write_v1 (const TopoDS_Shape& aShape, const Standard_CString aFileName) const;
Standard_EXPORT Standard_Boolean write_v1(const TopoDS_Shape& aShape,
const Standard_CString aFileName) const;
//! Converts the shape aShape to VRML format of version 2.0 and writes it
//! to the file identified by aFileName using default parameters.
Standard_EXPORT Standard_Boolean write_v2 (const TopoDS_Shape& aShape, const Standard_CString aFileName) const;
Standard_EXPORT Standard_Boolean write_v2(const TopoDS_Shape& aShape,
const Standard_CString aFileName) const;
private:
VrmlAPI_RepresentationOfShape myRepresentation;
Handle(VrmlConverter_Drawer) myDrawer;
Standard_Real myDeflection;
VrmlAPI_RepresentationOfShape myRepresentation;
Handle(VrmlConverter_Drawer) myDrawer;
Standard_Real myDeflection;
Handle(VrmlConverter_Projector) myPerespectiveCamera;
Handle(VrmlConverter_Projector) myOrthographicCamera;
Standard_Real myTransparency;
Standard_Real myShininess;
Handle(Vrml_Material) myFrontMaterial;
Handle(Vrml_Material) myPointsMaterial;
Handle(Vrml_Material) myUisoMaterial;
Handle(Vrml_Material) myVisoMaterial;
Handle(Vrml_Material) myLineMaterial;
Handle(Vrml_Material) myWireMaterial;
Handle(Vrml_Material) myFreeBoundsMaterial;
Handle(Vrml_Material) myUnfreeBoundsMaterial;
Standard_Real DX;
Standard_Real DY;
Standard_Real DZ;
Standard_Real XUp;
Standard_Real YUp;
Standard_Real ZUp;
Standard_Real Focus;
Standard_Real myTransparency;
Standard_Real myShininess;
Handle(Vrml_Material) myFrontMaterial;
Handle(Vrml_Material) myPointsMaterial;
Handle(Vrml_Material) myUisoMaterial;
Handle(Vrml_Material) myVisoMaterial;
Handle(Vrml_Material) myLineMaterial;
Handle(Vrml_Material) myWireMaterial;
Handle(Vrml_Material) myFreeBoundsMaterial;
Handle(Vrml_Material) myUnfreeBoundsMaterial;
Standard_Real DX;
Standard_Real DY;
Standard_Real DZ;
Standard_Real XUp;
Standard_Real YUp;
Standard_Real ZUp;
Standard_Real Focus;
};
#endif // _VrmlAPI_Writer_HeaderFile