-// Copyright (C) 2014-2020 CEA/DEN, EDF R&D
+// Copyright (C) 2014-2023 CEA, EDF
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
#include <TopoDS.hxx>
#include <Transfer_TransientProcess.hxx>
#include <TransferBRep.hxx>
+#include <TopTools_IndexedMapOfShape.hxx>
#include <XCAFApp_Application.hxx>
#include <XCAFDoc_DocumentTool.hxx>
#include <XCAFDoc_ShapeTool.hxx>
#include <XSControl_TransferReader.hxx>
#include <XSControl_WorkSession.hxx>
+#include <XCAFDoc_ColorTool.hxx>
+#include <XCAFDoc_MaterialTool.hxx>
#include <Locale_Convert.h>
+// read geometry
+std::shared_ptr<GeomAPI_Shape> setGeom(const Handle(XCAFDoc_ShapeTool) &shapeTool,
+ const TDF_Label &theLabel,
+ std::string& theError);
+
+/// read attributs for label
+void setShapeAttributes(const Handle(XCAFDoc_ShapeTool) &theShapeTool,
+ const Handle(XCAFDoc_ColorTool) &theColorTool,
+ const Handle(XCAFDoc_MaterialTool) &TheMaterialTool,
+ const TDF_Label &theLabel,
+ const TopLoc_Location &theLoc,
+ std::shared_ptr<ModelAPI_ResultBody> theResultBody,
+ std::map< std::wstring, std::list<std::wstring>> &theMaterialShape,
+ bool theIsRef);
+
+// store Materiel for theShapeLabel in the map theMaterialShape
+void storeMaterial(std::shared_ptr<ModelAPI_ResultBody> theResultBody,
+ const Handle(Standard_Transient) &theEnti,
+ const TopTools_IndexedMapOfShape &theIndices,
+ const Handle(Transfer_TransientProcess) &theTP,
+ const TDF_Label &theShapeLabel,
+ std::map< std::wstring, std::list<std::wstring>> &theMaterialShape);
+
//=============================================================================
TopoDS_Shape getShape(const Handle(Standard_Transient) &theEnti,
const Handle(Transfer_TransientProcess) &theTP)
setShapeAttributes(shapeTool, colorTool, materialTool, mainLabel,
TopLoc_Location(),theResultBody,theMaterialShape,false);
- std::shared_ptr<GeomAPI_Shape> ageom = setgeom(shapeTool,mainLabel,theError);
+ std::shared_ptr<GeomAPI_Shape> ageom = setGeom(shapeTool,mainLabel,theError);
STEPControl_Reader aReader = theReader.ChangeReader();
// BEGIN: reading materials of sub-shapes from file
- if ( theIsMaterials )
- {
+ if (theIsMaterials) {
TopTools_IndexedMapOfShape anIndices;
TopExp::MapShapes(ageom->impl<TopoDS_Shape>(), anIndices);
}
//=============================================================================
-std::shared_ptr<GeomAPI_Shape> setgeom(const Handle(XCAFDoc_ShapeTool) &theShapeTool,
- const TDF_Label &theLabel,
+std::shared_ptr<GeomAPI_Shape> setGeom(const Handle(XCAFDoc_ShapeTool) &theShapeTool,
+ const TDF_Label& /*theLabel*/,
std::string& theError)
{
BRep_Builder aB;
aGeomShape->setImpl(new TopoDS_Shape(shape));
return aGeomShape;
} else {
- for (Standard_Integer i=1; i<aFrshapes.Length(); i++) {
+ for (Standard_Integer i=1; i<=aFrshapes.Length(); i++) {
TopoDS_Shape aS = theShapeTool->GetShape(aFrshapes.Value(i));
TDF_Label aLabel = theShapeTool->FindShape(aS, Standard_False);
if ( (!aLabel.IsNull()) && (theShapeTool->IsShape(aLabel)) ) {
if (aS.IsNull()) {
continue;
} else {
- if (!theShapeTool->IsReference(aLabel) ){
+ if (aS.ShapeType() != TopAbs_SOLID && !theShapeTool->IsReference(aLabel)){
for(TDF_ChildIterator anIt(aLabel); anIt.More(); anIt.Next()) {
aB.Add(aCompound, theShapeTool->GetShape(anIt.Value()) );
}
TopoDS_Shape aShape = aCompound;
// Check if any BRep entity has been read, there must be at least a vertex
- if ( !TopExp_Explorer( aShape, TopAbs_VERTEX ).More() )
- {
+ if (!TopExp_Explorer( aShape, TopAbs_VERTEX ).More()) {
theError = "No geometrical data in the imported file.";
- std::shared_ptr<GeomAPI_Shape> aGeomShape(new GeomAPI_Shape);
aGeomShape->setImpl(new TopoDS_Shape());
return aGeomShape;
}
TopoDS_Shape aShape = theShapeTool->GetShape(theLabel);
std::shared_ptr<GeomAPI_Shape> aShapeGeom(new GeomAPI_Shape);
- if (!theLoc.IsIdentity()){
+ if (!theLoc.IsIdentity()) {
aShape.Move(theLoc);
}
aShapeGeom->setImpl(new TopoDS_Shape(aShape));
std::vector<int> aColRGB = {int(r*255),int(g*255),int(b*255)};
theResultBody->addShapeColor(aShapeName, aColRGB);
} else if (theColorTool->GetColor(theLabel, XCAFDoc_ColorCurv, aCol)) {
- double aR = aCol.Red(), aG = aCol.Green(), aB = aCol.Blue();
- std::vector<int> aColRGB = {int(aR*255),int(aG*255),int(aB*255)};
+ double aR = aCol.Red(), aG = aCol.Green(), aB = aCol.Blue();
+ std::vector<int> aColRGB = {int(aR*255),int(aG*255),int(aB*255)};
theResultBody->addShapeColor(aShapeName, aColRGB);
}
// check explicit coloring of boundary entities
if (aDim == 3) {
TopExp_Explorer aXp2(aShape, TopAbs_FACE);
- while(aXp2.More()) {
+ while (aXp2.More()) {
if (theColorTool->GetColor(aXp2.Current(), XCAFDoc_ColorGen, aCol) ||
- theColorTool->GetColor(aXp2.Current(), XCAFDoc_ColorSurf, aCol) ||
- theColorTool->GetColor(aXp2.Current(), XCAFDoc_ColorCurv, aCol)) {
+ theColorTool->GetColor(aXp2.Current(), XCAFDoc_ColorSurf, aCol) ||
+ theColorTool->GetColor(aXp2.Current(), XCAFDoc_ColorCurv, aCol)) {
double aR = aCol.Red(), aG = aCol.Green(), aB = aCol.Blue();
TopoDS_Face aFace = TopoDS::Face(aXp2.Current());
std::vector<int> aColRGB = {int(aR*255),int(aG*255),int(aB*255)};
aXp2.Next();
}
}
- if (aDim == 2) {
- TopExp_Explorer aXp1(aShape, TopAbs_EDGE);
- while(aXp1.More()) {
- if (theColorTool->GetColor(aXp1.Current(), XCAFDoc_ColorGen, aCol) ||
- theColorTool->GetColor(aXp1.Current(), XCAFDoc_ColorSurf, aCol) ||
- theColorTool->GetColor(aXp1.Current(), XCAFDoc_ColorCurv, aCol)) {
- double aR = aCol.Red(), aG = aCol.Green(), aB = aCol.Blue();
- std::vector<int> aColRGB = {int(aR*255),int(aG*255),int(aB*255)};
- std::wstringstream aNameEdge;
- aNameEdge << L"Edge_"<< aShapeName;
- aShapeGeom->setImpl(new TopoDS_Shape(aXp1.Current() ));
- theResultBody->addShapeColor(
- theResultBody->addShapeName(aShapeGeom , aNameEdge.str()), aColRGB);
- }
- aXp1.Next();
- }
- }
} else {
if (!theShapeTool->IsReference(theLabel) ){
TopoDS_Shape aShape = theShapeTool->GetShape(theLabel);
const Handle(Standard_Transient) &theEnti,
const TopTools_IndexedMapOfShape &theIndices,
const Handle(Transfer_TransientProcess) &theTP,
- const TDF_Label &theShapeLabel,
+ const TDF_Label &/*theShapeLabel*/,
std::map< std::wstring, std::list<std::wstring>> &theMaterialShape )
{
// Treat Product Definition Shape only.
}
}
}
-