Part_1_doc = Part_1.document()
aShapePath = os.path.join(os.getenv("DATA_DIR"), "Shapes", "Step", "black_and_white.step")
print("aShapePath=",aShapePath)
- Import_1 = model.addImportStep(Part_1_doc,aShapePath, True, True, True)
+ Import_1 = model.addImportSTEP(Part_1_doc,aShapePath, True, True, True)
model.do()
//--------------------------------------------------------------------------------------
void ExchangeAPI_Import::setFilePath(const std::string & theFilePath)
{
-
+
std::string anExtension = GeomAlgoAPI_Tools::File_Tools::extension(theFilePath);
if (anExtension == "STEP" || anExtension == "STP") {
setParameters(theFilePath,true,false,false);
- }else{
+ } else {
fillAttribute(theFilePath, myfilePath);
fillAttribute(anExtension, myimportType);
execute();
if (aFormat == "STEP" || aFormat == "STP")
{
aFilePath = aBase->string(ExchangePlugin_ImportFeature::STEP_FILE_PATH_ID())->value();
- }else{
+ } else {
aFilePath = aBase->string(ExchangePlugin_ImportFeature::FILE_PATH_ID())->value();
}
aPos += aTo.size();
}
std::string anExtension = GeomAlgoAPI_Tools::File_Tools::extension(aFilePath);
- if( anExtension == "STP" || anExtension == "STEP"){
- theDumper << aBase << " = model.addImportStep(" << aPartName << ", \""
+ if (anExtension == "STP" || anExtension == "STEP"){
+ theDumper << aBase << " = model.addImportSTEP(" << aPartName << ", \""
<< aFilePath << "\"" ;
theDumper << ", " << scalInterUnits()->value()
<< ", " << materials()->value()
<< ", " << colors()->value() << ")"<< std::endl;
- }else{
+ } else {
theDumper << aBase << " = model.addImport(" << aPartName << ", \""
<< aFilePath << "\")" << std::endl;
}
CompositeFeaturePtr aCompositeFeature =
std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aBase);
- if(aCompositeFeature.get()) {
+ if (aCompositeFeature.get()) {
int aNbOfSubs = aCompositeFeature->numberOfSubs();
for(int anIndex = 0; anIndex < aNbOfSubs; ++anIndex) {
std::string aSubFeatureGet =
return ImportPtr(new ExchangeAPI_Import(aFeature, theFilePath));
}
-ImportPtr addImportStep(
+ImportPtr addImportSTEP(
const std::shared_ptr<ModelAPI_Document> & thePart,
const std::string & theFilePath,
const bool theScalInterUnits,
* \brief Create Import Step feature
*/
EXCHANGEAPI_EXPORT
-ImportPtr addImportStep(const std::shared_ptr<ModelAPI_Document> & thePart,
+ImportPtr addImportSTEP(const std::shared_ptr<ModelAPI_Document> & thePart,
const std::string & theFilePath,
const bool anScalInterUnits,
const bool anMaterials,
DocumentPtr aDoc = ModelAPI_Session::get()->moduleDocument();
int aFeaturesNb = aDoc->size(ModelAPI_Feature::group());
- if(aFeaturesNb > 1) {
+ if (aFeaturesNb > 1) {
FeaturePtr aLastFeature =
ModelAPI_Feature::feature(aDoc->object(ModelAPI_Feature::group(), aFeaturesNb - 1));
- if(aDoc->currentFeature(true) != aLastFeature) {
+ if (aDoc->currentFeature(true) != aLastFeature) {
setError("Dump cannot be done. Please move the history line to the end before dumping.");
return;
}
DocumentPtr anActiveDoc = ModelAPI_Session::get()->activeDocument();
aFeaturesNb = anActiveDoc->size(ModelAPI_Feature::group());
- if(aFeaturesNb > 1) {
+ if (aFeaturesNb > 1) {
FeaturePtr aLastFeature =
ModelAPI_Feature::feature(anActiveDoc->object(ModelAPI_Feature::group(), aFeaturesNb - 1));
- if(anActiveDoc->currentFeature(true) != aLastFeature) {
+ if (anActiveDoc->currentFeature(true) != aLastFeature) {
setError("Dump cannot be done. Please move the history line to the end before dumping.");
return;
}
if (aFormat == "STEP" || aFormat == "STP")
{
aFilePathAttr = string(ExchangePlugin_ImportFeature::STEP_FILE_PATH_ID());
- }else{
+ } else {
aFilePathAttr = string(ExchangePlugin_ImportFeature::FILE_PATH_ID());
}
std::string aFilePath = aFilePathAttr->value();
for(std::list<ResultPtr>::iterator aRes = allRes.begin(); aRes != allRes.end(); ++aRes) {
ModelAPI_Tools::getColor(*aRes, aColor);
if (!aColor.empty() ){
- auto it = std::find(aColorsRead.begin(), aColorsRead.end(), aColor);
- if ( it == aColorsRead.end() ){
- std::wstringstream aColorName;
- aColorName<<L"Color_"<< anIndice;
- setColorGroup(theResultBody, aColor, aColorName.str());
- anIndice++;
- aColorsRead.push_back(aColor);
- }
+ auto it = std::find(aColorsRead.begin(), aColorsRead.end(), aColor);
+ if ( it == aColorsRead.end() ){
+ std::wstringstream aColorName;
+ aColorName<<L"Color_"<< anIndice;
+ setColorGroup(theResultBody, aColor, aColorName.str());
+ anIndice++;
+ aColorsRead.push_back(aColor);
+ }
}
}
}
ModelAPI_Tools::getColor(theResultBody, aColor);
if (!aColor.empty() ){
- if( aColor == theColor ) {
+ if (aColor == theColor ) {
GeomShapePtr aShape = theResultBody->shape();
aSelectionList->setSelectionType(aShape->shapeTypeStr() );
aSelectionList->append(theResultBody,aShape);
GeomShapePtr aShape = (*aRes)->shape();
if (!aColor.empty() ){
- if( aRes->get() && aColor == theColor ) {
- aSelectionList->setSelectionType(aShape->shapeTypeStr() );
- aSelectionList->append(theResultBody,aShape);
+ if (aRes->get() && aColor == theColor ) {
+ aSelectionList->setSelectionType(aShape->shapeTypeStr() );
+ aSelectionList->append(theResultBody,aShape);
}
}
}
GeomShapePtr aShape = (*aRes)->shape();
for(std::list<std::wstring>::iterator aResMat = anIt->second.begin();
aResMat != anIt->second.end(); ++aResMat) {
- if( aRes->get() && ((*aRes)->data()->name() == (*aResMat)))
+ if (aRes->get() && ((*aRes)->data()->name() == (*aResMat)))
{
aSelectionList->append(theResultBody,aShape);
aSelectionList->setSelectionType(aShape->shapeTypeStr() );
/// Loads Naming data structure to the document
void loadNamingDS(std::shared_ptr<GeomAPI_Shape> theGeomShape,
std::shared_ptr<ModelAPI_ResultBody> theResultBody);
- // Set groups of color
+ /// Set groups of color
void setColorGroups(std::shared_ptr<ModelAPI_ResultBody> theResultBody);
- // set a group of color
+ /// set a group of color
void setColorGroup(std::shared_ptr<ModelAPI_ResultBody> theResultBody,
std::vector<int> &aColor,
const std::wstring& theName );
- // set Materiel group of color
+ /// set Materiel group of color
void setMaterielGroup(std::shared_ptr<ModelAPI_ResultBody> theResultBody,
std::map< std::wstring, std::list<std::wstring>> &theMaterialShape);
Part_1_doc = Part_1.document()
aShapePath = os.path.join(os.getenv("DATA_DIR"), "Shapes", "Step", "black_and_white.step")
print("aShapePath=",aShapePath)
- Import_1 = model.addImportStep(Part_1_doc,aShapePath, True, True, True)
+ Import_1 = model.addImportSTEP(Part_1_doc,aShapePath, True, True, True)
model.do()
partSet = model.moduleDocument()
Part_1 = model.addPart(partSet)
Part_1_doc = Part_1.document()
-Import_1 = model.addImportStep(Part_1_doc,file_path, True, True, True)
+Import_1 = model.addImportSTEP(Part_1_doc,file_path, True, True, True)
model.do()
model.end()
**TUI Command**:
-.. py:function:: model.addImportStep(Part_doc, FileNameString,scalInterUnits,materials,colors)
+.. py:function:: model.addImportSTEP(Part_doc, FileNameString,scalInterUnits,materials,colors)
:param part: The current part object
:param string: A file name string.
</feature>
<feature id="Import" title="Import" tooltip="Import a file" icon="icons/Exchange/import.png"
helpfile="importFeature.html" internal="1">
- <!--file_selector id="file_path" title="Import file" path="">
- <validator id="ExchangePlugin_ImportFormat" parameters="BREP|BRP:BREP,STEP|STP:STEP,IGES|IGS:IGES,XAO:XAO" />
- </file_selector-->
<switch id="ImportType">
- <case id="Regular" title="BREP, XAO, IGES">
- <file_selector id="file_path" title="Import file" path="">
- <validator id="ExchangePlugin_ImportFormat" parameters="BREP|BRP:BREP,IGES|IGS:IGES,XAO:XAO" />
- </file_selector>
- </case>
- <case id="STEP" title="STEP">
+ <case id="Regular" title="BREP, XAO, IGES">
+ <file_selector id="file_path" title="Import file" path="">
+ <validator id="ExchangePlugin_ImportFormat" parameters="BREP|BRP:BREP,IGES|IGS:IGES,XAO:XAO" />
+ </file_selector>
+ </case>
+ <case id="STEP" title="STEP">
<file_selector id="step_file_path" title="Import file" path="">
<validator id="ExchangePlugin_ImportFormat" parameters="STEP|STP:STEP" />
</file_selector>
const std::shared_ptr<ModelAPI_Feature>& theFeature,
const std::list<ModelHighAPI_Selection>& theObjects) : ModelHighAPI_Interface(theFeature)
{
- if(initialize()) {
+ if (initialize()) {
setObjects(theObjects);
}
}
//
#include <GeomAlgoAPI_STEPImport.h>
+#include <GeomAlgoAPI_STEPImportXCAF.h>
#include <TDF_ChildIDIterator.hxx>
#include <TDF_Label.hxx>
#include <Interface_Graph.hxx>
#include <Interface_InterfaceModel.hxx>
#include <Interface_Static.hxx>
+
+#include <STEPCAFControl_Reader.hxx>
#include <STEPControl_Reader.hxx>
#include <StepBasic_Product.hxx>
#include <StepBasic_ProductDefinition.hxx>
#include <TopoDS_Compound.hxx>
#include <TopoDS_Iterator.hxx>
-//JL_CGLB
-#include <XCAFApp_Application.hxx>
-#include <XCAFDoc_DocumentTool.hxx>
-#include <OSD_Exception.hxx>
-#include <STEPCAFControl_Reader.hxx>
-#include <TDocStd_Document.hxx>
-#include <XCAFDoc_ColorTool.hxx>
-#include <XCAFDoc_ShapeTool.hxx>
-#include <GeomAlgoAPI_STEPImportXCAF.h>
-#include <Quantity_Color.hxx>
-
-#include <TColStd_SequenceOfAsciiString.hxx>
-#include <TCollection_ExtendedString.hxx>
-
-#include <Standard_Failure.hxx>
#include <Standard_ErrorHandler.hxx> // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC
-// ----------------------------------------------------------------------------
+//==================================================================================================
std::shared_ptr<GeomAPI_Shape> STEPImport(const std::string& theFileName,
const std::string& theFormatName,
const bool theScalInterUnits,
return aGeomShape;
}
-
-std::shared_ptr<GeomAPI_Shape> STEPImportAttributs(const std::string& theFileName,
- std::shared_ptr<ModelAPI_ResultBody> theResultBody,
- const bool theScalInterUnits,
- const bool theMaterials,
- const bool theColor,
- std::map< std::wstring,
- std::list<std::wstring>> &theMaterialShape,
- std::string& theError)
+//==================================================================================================
+GeomShapePtr STEPImportAttributs(const std::string& theFileName,
+ std::shared_ptr<ModelAPI_ResultBody> theResultBody,
+ const bool theScalInterUnits,
+ const bool theMaterials,
+ const bool theColor,
+ std::map< std::wstring,
+ std::list<std::wstring>> &theMaterialShape,
+ std::string& theError)
{
STEPControl_Reader aReader;
std::shared_ptr<GeomAPI_Shape> aGeomShape(new GeomAPI_Shape);
- //VSR: 16/09/09: Convert to METERS
+
Interface_Static::SetCVal("xstep.cascade.unit","M");
Interface_Static::SetIVal("read.step.ideas", 1);
Interface_Static::SetIVal("read.step.nonmanifold", 1);
theMaterials,
theMaterialShape,
theError);
-}
-
+}
\ No newline at end of file
/// Implementation of the import STEP files algorithms with Attributs (Name, Color, Materials)
GEOMALGOAPI_EXPORT
-std::shared_ptr<GeomAPI_Shape> STEPImportAttributs(const std::string& theFileName,
- std::shared_ptr<ModelAPI_ResultBody> theResultBody,
- const bool anScalInterUnits,
- const bool anMaterials,
- const bool anColor,
- std::map< std::wstring,
- std::list<std::wstring>> &theMaterialShape,
- std::string& theError);
+GeomShapePtr STEPImportAttributs(const std::string& theFileName,
+ std::shared_ptr<ModelAPI_ResultBody> theResultBody,
+ const bool anScalInterUnits,
+ const bool anMaterials,
+ const bool anColor,
+ std::map< std::wstring,
+ std::list<std::wstring>> &theMaterialShape,
+ std::string& theError);
#endif /* GEOMALGOAPI_STEPIMPORT_H_ */
#include <GeomAlgoAPI_STEPImportXCAF.h>
-#include <TDF_ChildIDIterator.hxx>
-#include <TDF_Label.hxx>
-#include <TDataStd_Name.hxx>
-#include <TDataStd_Comment.hxx>
-#include <TNaming_Builder.hxx>
-#include <TNaming_NamedShape.hxx>
+#include <BRep_Builder.hxx>
-#include <IFSelect_ReturnStatus.hxx>
#include <Interface_EntityIterator.hxx>
#include <Interface_Graph.hxx>
#include <Interface_InterfaceModel.hxx>
-#include <Interface_Static.hxx>
-#include <STEPControl_Reader.hxx>
-#include <StepBasic_Product.hxx>
-#include <StepBasic_ProductDefinition.hxx>
-#include <StepBasic_ProductDefinitionFormation.hxx>
-#include <StepGeom_GeometricRepresentationItem.hxx>
-#include <StepShape_TopologicalRepresentationItem.hxx>
+
+#include <Quantity_Color.hxx>
+
#include <StepRepr_DescriptiveRepresentationItem.hxx>
#include <StepRepr_ProductDefinitionShape.hxx>
#include <StepRepr_PropertyDefinitionRepresentation.hxx>
#include <StepRepr_Representation.hxx>
-#include <TransferBRep.hxx>
-#include <Transfer_Binder.hxx>
-#include <Transfer_TransientProcess.hxx>
-#include <XSControl_TransferReader.hxx>
-#include <XSControl_WorkSession.hxx>
-
-#include <BRep_Builder.hxx>
+#include <TDataStd_Name.hxx>
+#include <TDF_ChildIDIterator.hxx>
+#include <TDocStd_Document.hxx>
#include <TopExp.hxx>
#include <TopExp_Explorer.hxx>
-#include <TopTools_IndexedMapOfShape.hxx>
-#include <TopoDS_Compound.hxx>
-#include <TopoDS_Iterator.hxx>
+#include <TopoDS.hxx>
+#include <Transfer_TransientProcess.hxx>
+#include <TransferBRep.hxx>
#include <XCAFApp_Application.hxx>
#include <XCAFDoc_DocumentTool.hxx>
-#include <OSD_Exception.hxx>
-#include <Locale_Convert.h>
-
-#include <TDocStd_Document.hxx>
-#include <XCAFDoc_ColorTool.hxx>
-#include <XCAFDoc_ShapeTool.hxx>
-#include <XCAFDoc_MaterialTool.hxx>
-#include <Quantity_Color.hxx>
-#include <TopoDS.hxx>
-#include <STEPConstruct.hxx>
-#include <STEPConstruct_Tool.hxx>
-#include <StepBasic_ProductDefinitionRelationship.hxx>
-#include <StepRepr_NextAssemblyUsageOccurrence.hxx>
#include <XCAFDoc_Location.hxx>
+#include <XCAFDoc_ShapeTool.hxx>
+#include <XSControl_TransferReader.hxx>
+#include <XSControl_WorkSession.hxx>
-#include <TColStd_SequenceOfAsciiString.hxx>
-
-#include <Standard_Failure.hxx>
-#include <Standard_ErrorHandler.hxx> // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC
-
+#include <Locale_Convert.h>
//=============================================================================
-/*!
- * GetShape()
- */
-//=============================================================================
-
TopoDS_Shape getShape(const Handle(Standard_Transient) &theEnti,
const Handle(Transfer_TransientProcess) &theTP)
{
return aResult;
}
-// ----------------------------------------------------------------------------
-
-std::shared_ptr<GeomAPI_Shape> readAttributes(
- STEPCAFControl_Reader &theReader,
- std::shared_ptr<ModelAPI_ResultBody> theResultBody,
- const bool theIsMaterials,
- std::map< std::wstring,std::list<std::wstring>> &theMaterialShape,
- std::string& theError)
+//=============================================================================
+std::shared_ptr<GeomAPI_Shape> readAttributes(STEPCAFControl_Reader &theReader,
+ std::shared_ptr<ModelAPI_ResultBody> theResultBody,
+ const bool theIsMaterials,
+ std::map< std::wstring,std::list<std::wstring>> &theMaterialShape,
+ std::string& theError)
{
// dummy XCAF Application to handle the STEP XCAF Document
Handle(XCAFApp_Application) dummy_app = XCAFApp_Application::GetApplication();
return ageom;
}
+//=============================================================================
std::shared_ptr<GeomAPI_Shape> setgeom(const Handle(XCAFDoc_ShapeTool) &theShapeTool,
const TDF_Label &theLabel,
std::string& theError)
if (theShapeTool->IsFree(aLabel) ) {
if (aS.IsNull()) {
continue;
- }
- else {
+ } else {
if (!theShapeTool->IsReference(aLabel) ){
for(TDF_ChildIterator anIt(aLabel); anIt.More(); anIt.Next()) {
aB.Add(aCompound, theShapeTool->GetShape(anIt.Value()) );
}
- }else{
+ } else {
aB.Add(aCompound, aS);
}
}
return aGeomShape;
}
}
-
+//=============================================================================
void setShapeAttributes(const Handle(XCAFDoc_ShapeTool) &theShapeTool,
const Handle(XCAFDoc_ColorTool) &theColorTool,
const Handle(XCAFDoc_MaterialTool) &theMaterialTool,
std::wstring aShapeName;
Handle(TDataStd_Name) aN;
- if(theLabel.FindAttribute(TDataStd_Name::GetID(), aN)) {
+ if (theLabel.FindAttribute(TDataStd_Name::GetID(), aN)) {
TCollection_ExtendedString aName = aN->Get();
aShapeName = Locale::Convert::toWString(TCollection_AsciiString(aName).ToCString()) ;
TopLoc_Location aPartLoc = theLoc;
Handle(XCAFDoc_Location) al;
- if(theLabel.FindAttribute(XCAFDoc_Location::GetID(), al)) {
- if(theIsRef)
+ if (theLabel.FindAttribute(XCAFDoc_Location::GetID(), al)) {
+ if (theIsRef)
aPartLoc = aPartLoc * al->Get();
else
aPartLoc = al->Get();
}
TDF_Label aRef;
- if(theShapeTool->IsReference(theLabel) && theShapeTool->GetReferredShape(theLabel, aRef)) {
+ if (theShapeTool->IsReference(theLabel) && theShapeTool->GetReferredShape(theLabel, aRef)) {
setShapeAttributes( theShapeTool, theColorTool, theMaterialTool, aRef,
aPartLoc,theResultBody,theMaterialShape,true);
}
- if( theShapeTool->IsSimpleShape(theLabel) && (theIsRef || theShapeTool->IsFree(theLabel))) {
+ if (theShapeTool->IsSimpleShape(theLabel) && (theIsRef || theShapeTool->IsFree(theLabel))) {
TopoDS_Shape aShape = theShapeTool->GetShape(theLabel);
Handle(TCollection_HAsciiString) aMatDensName;
Handle(TCollection_HAsciiString) aMatDensValType;
- if(theMaterialTool->GetMaterial(theLabel, aMatName, aMatDescription, aMatDensity,
+ if (theMaterialTool->GetMaterial(theLabel, aMatName, aMatDescription, aMatDensity,
aMatDensName, aMatDensValType)) {
std::wstring aNameMaterial = Locale::Convert::toWString(aMatName->ToCString());
}
Quantity_Color aCol;
- if(theColorTool->GetColor(theLabel, XCAFDoc_ColorGen, aCol)) {
+ if (theColorTool->GetColor(theLabel, XCAFDoc_ColorGen, aCol)) {
double r = aCol.Red(), g = aCol.Green(), b = aCol.Blue();
std::vector<int> ColRGB = {int(r*255),int(g*255),int(b*255)};
theResultBody->addShapeColor(aShapeName, ColRGB);
- }
- else if(theColorTool->GetColor(theLabel, XCAFDoc_ColorSurf, aCol)) {
+ } else if (theColorTool->GetColor(theLabel, XCAFDoc_ColorSurf, aCol)) {
double r = aCol.Red(), g = aCol.Green(), b = aCol.Blue();
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)) {
+ } 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)};
theResultBody->addShapeColor(aShapeName, aColRGB);
}
// check explicit coloring of boundary entities
- if(aDim == 3) {
+ if (aDim == 3) {
TopExp_Explorer aXp2(aShape, TopAbs_FACE);
while(aXp2.More()) {
- if(theColorTool->GetColor(aXp2.Current(), XCAFDoc_ColorGen, aCol) ||
+ if (theColorTool->GetColor(aXp2.Current(), XCAFDoc_ColorGen, 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();
aXp2.Next();
}
}
- if(aDim == 2) {
+ if (aDim == 2) {
TopExp_Explorer aXp1(aShape, TopAbs_EDGE);
while(aXp1.More()) {
- if(theColorTool->GetColor(aXp1.Current(), XCAFDoc_ColorGen, aCol) ||
+ 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();
aXp1.Next();
}
}
- }
- else {
+ } else {
if (!theShapeTool->IsReference(theLabel) ){
TopoDS_Shape aShape = theShapeTool->GetShape(theLabel);
}
}
-
//=============================================================================
- /*!
- * StoreMaterial()
- */
- //=============================================================================
-
- 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 )
- {
- // Treat Product Definition Shape only.
- Handle(StepRepr_ProductDefinitionShape) aPDS =
- Handle(StepRepr_ProductDefinitionShape)::DownCast(theEnti);
- Handle(StepBasic_ProductDefinition) aProdDef;
-
- if(aPDS.IsNull() == Standard_False) {
- // Product Definition Shape ==> Product Definition
- aProdDef = aPDS->Definition().ProductDefinition();
- }
-
- if (aProdDef.IsNull() == Standard_False) {
- // Product Definition ==> Property Definition
- const Interface_Graph &aGraph = theTP->Graph();
- Interface_EntityIterator aSubs = aGraph.Sharings(aProdDef);
- TopoDS_Shape aShape;
-
- for(aSubs.Start(); aSubs.More(); aSubs.Next()) {
- Handle(StepRepr_PropertyDefinition) aPropD =
- Handle(StepRepr_PropertyDefinition)::DownCast(aSubs.Value());
-
- if(aPropD.IsNull() == Standard_False) {
- // Property Definition ==> Representation.
- Interface_EntityIterator aSubs1 = aGraph.Sharings(aPropD);
-
- for(aSubs1.Start(); aSubs1.More(); aSubs1.Next()) {
- Handle(StepRepr_PropertyDefinitionRepresentation) aPDR =
- Handle(StepRepr_PropertyDefinitionRepresentation)::
- DownCast(aSubs1.Value());
-
- if(aPDR.IsNull() == Standard_False) {
- // Property Definition ==> Material Name.
- Handle(StepRepr_Representation) aRepr = aPDR->UsedRepresentation();
-
- if(aRepr.IsNull() == Standard_False) {
- Standard_Integer anIr;
-
- for(anIr = 1; anIr <= aRepr->NbItems(); anIr++) {
- Handle(StepRepr_RepresentationItem) aRI = aRepr->ItemsValue(anIr);
- Handle(StepRepr_DescriptiveRepresentationItem) aDRI =
- Handle(StepRepr_DescriptiveRepresentationItem)::DownCast(aRI);
-
- if(aDRI.IsNull() == Standard_False) {
- // Get shape from Product Definition
- Handle(TCollection_HAsciiString) aMatName = aDRI->Name();
- if(aMatName.IsNull() == Standard_False) {
- TCollection_ExtendedString
- aMatNameExt (aMatName->ToCString());
+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 )
+{
+ // Treat Product Definition Shape only.
+ Handle(StepRepr_ProductDefinitionShape) aPDS =
+ Handle(StepRepr_ProductDefinitionShape)::DownCast(theEnti);
+ Handle(StepBasic_ProductDefinition) aProdDef;
+
+ if (aPDS.IsNull() == Standard_False) {
+ // Product Definition Shape ==> Product Definition
+ aProdDef = aPDS->Definition().ProductDefinition();
+ }
+ if (aProdDef.IsNull() == Standard_False) {
+ // Product Definition ==> Property Definition
+ const Interface_Graph &aGraph = theTP->Graph();
+ Interface_EntityIterator aSubs = aGraph.Sharings(aProdDef);
+ TopoDS_Shape aShape;
+
+ for(aSubs.Start(); aSubs.More(); aSubs.Next()) {
+ Handle(StepRepr_PropertyDefinition) aPropD =
+ Handle(StepRepr_PropertyDefinition)::DownCast(aSubs.Value());
+
+ if (aPropD.IsNull() == Standard_False) {
+ // Property Definition ==> Representation.
+ Interface_EntityIterator aSubs1 = aGraph.Sharings(aPropD);
+
+ for(aSubs1.Start(); aSubs1.More(); aSubs1.Next()) {
+ Handle(StepRepr_PropertyDefinitionRepresentation) aPDR =
+ Handle(StepRepr_PropertyDefinitionRepresentation)::
+ DownCast(aSubs1.Value());
+
+ if (aPDR.IsNull() == Standard_False) {
+ // Property Definition ==> Material Name.
+ Handle(StepRepr_Representation) aRepr = aPDR->UsedRepresentation();
+
+ if (aRepr.IsNull() == Standard_False) {
+ Standard_Integer anIr;
+
+ for(anIr = 1; anIr <= aRepr->NbItems(); anIr++) {
+ Handle(StepRepr_RepresentationItem) aRI = aRepr->ItemsValue(anIr);
+ Handle(StepRepr_DescriptiveRepresentationItem) aDRI =
+ Handle(StepRepr_DescriptiveRepresentationItem)::DownCast(aRI);
+
+ if (aDRI.IsNull() == Standard_False) {
+ // Get shape from Product Definition
+ Handle(TCollection_HAsciiString) aMatName = aDRI->Name();
+ if (aMatName.IsNull() == Standard_False) {
+ TCollection_ExtendedString
+ aMatNameExt (aMatName->ToCString());
+
+ if (aShape.IsNull()) {
+ //Get the shape.
+ aShape = getShape(aProdDef, theTP);
if (aShape.IsNull()) {
- //Get the shape.
- aShape = getShape(aProdDef, theTP);
- if (aShape.IsNull()) {
- return;
- }
+ return;
}
+ }
- // as PRODUCT can be included in the main shape
- // several times, we look here for all iclusions.
- Standard_Integer anISub, aNbSubs = theIndices.Extent();
+ // as PRODUCT can be included in the main shape
+ // several times, we look here for all iclusions.
+ Standard_Integer anISub, aNbSubs = theIndices.Extent();
- for (anISub = 1; anISub <= aNbSubs; anISub++) {
- TopoDS_Shape aSub = theIndices.FindKey(anISub);
+ for (anISub = 1; anISub <= aNbSubs; anISub++) {
+ TopoDS_Shape aSub = theIndices.FindKey(anISub);
- if (aSub.IsPartner(aShape)) {
- std::shared_ptr<GeomAPI_Shape> aShapeGeom(new GeomAPI_Shape);
- aShapeGeom->setImpl(new TopoDS_Shape(aSub));
- std::wstring aNom = theResultBody->findShapeName(aShapeGeom);
- std::wstring aMName= Locale::Convert::toWString(aMatName->ToCString());
- theMaterialShape[aMName].push_back(aNom);
+ if (aSub.IsPartner(aShape)) {
+ std::shared_ptr<GeomAPI_Shape> aShapeGeom(new GeomAPI_Shape);
+ aShapeGeom->setImpl(new TopoDS_Shape(aSub));
+ std::wstring aNom = theResultBody->findShapeName(aShapeGeom);
+ std::wstring aMName= Locale::Convert::toWString(aMatName->ToCString());
+ theMaterialShape[aMName].push_back(aNom);
- }
}
}
}
}
}
}
+}
#define GEOMALGOAPI_STEPIMPORTXCAF_H_
#include <GeomAlgoAPI.h>
-#include <TopoDS_Shape.hxx>
-#include <string>
-#include <vector>
-#include <map>
-#include <set>
-#include <GeomAPI_Shape.h>
#include <XCAFDoc_ColorTool.hxx>
-#include <XCAFDoc_ShapeTool.hxx>
#include <XCAFDoc_MaterialTool.hxx>
-#include <TDocStd_Document.hxx>
-#include <XSControl_WorkSession.hxx>
#include <STEPCAFControl_Reader.hxx>
#include <ModelAPI_ResultBody.h>
#include <TopTools_IndexedMapOfShape.hxx>
- // read Attributs of step file
+ /// read Attributs of step file
GEOMALGOAPI_EXPORT
- std::shared_ptr<GeomAPI_Shape> readAttributes(
- STEPCAFControl_Reader &theReader,
- std::shared_ptr<ModelAPI_ResultBody> theResultBody,
- const bool theMaterials,
- std::map< std::wstring,std::list<std::wstring>> &theMaterialShape,
- std::string& theError);
-// read attributs for label
+ std::shared_ptr<GeomAPI_Shape> readAttributes(STEPCAFControl_Reader &theReader,
+ std::shared_ptr<ModelAPI_ResultBody> theResultBody,
+ const bool theMaterials,
+ std::map< std::wstring,std::list<std::wstring>> &theMaterialShape,
+ std::string& theError);
+/// read attributs for label
GEOMALGOAPI_EXPORT
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);
+ 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);
// read geometry
GEOMALGOAPI_EXPORT
// store Materiel for theShapeLabel in the map theMaterialShape
GEOMALGOAPI_EXPORT
-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 );
+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);
#endif /* GEOMALGOAPI_STEPIMPORTXCAF_H_ */
if (aShape.IsNull())
return; // null shape inside
- if(!theIsStoreSameShapes) {
+ if (!theIsStoreSameShapes) {
Handle(TNaming_NamedShape) aNS;
if (TNaming_Tool::HasLabel(aShapeLab, aShape))
aNS = TNaming_Tool::NamedShape(aShape, aShapeLab);
// the last condition is for the issue 2751 : existing shape may be found in compound-NS
- if(!aNS.IsNull() && !aNS->IsEmpty() && aNS->Get().IsSame(aShape)) {
+ if (!aNS.IsNull() && !aNS->IsEmpty() && aNS->Get().IsSame(aShape)) {
// This shape is already in document, store reference instead of shape;
const TDF_Label aFoundLabel = aNS->Label();
TDF_Reference::Set(aShapeLab, aFoundLabel);
aBuilder.Generated(aShape);
// register name
aShapeLab.ForgetAttribute(TDF_Reference::GetID());
- if(!aBuilder.NamedShape()->IsEmpty()) {
+ if (!aBuilder.NamedShape()->IsEmpty()) {
Handle(TDataStd_Name) anAttr;
- if(aBuilder.NamedShape()->Label().FindAttribute(TDataStd_Name::GetID(),anAttr)) {
+ if (aBuilder.NamedShape()->Label().FindAttribute(TDataStd_Name::GetID(),anAttr)) {
std::wstring aName = Locale::Convert::toWString(anAttr->Get().ToExtString());
- if(!aName.empty()) {
+ if (!aName.empty()) {
std::shared_ptr<Model_Document> aDoc =
std::dynamic_pointer_cast<Model_Document>(document());
aDoc->addNamingName(aBuilder.NamedShape()->Label(), aName);
}
// register name
- if(!aBuilder->NamedShape()->IsEmpty()) {
+ if (!aBuilder->NamedShape()->IsEmpty()) {
Handle(TDataStd_Name) anAttr;
- if(aBuilder->NamedShape()->Label().FindAttribute(TDataStd_Name::GetID(),anAttr)) {
+ if (aBuilder->NamedShape()->Label().FindAttribute(TDataStd_Name::GetID(),anAttr)) {
std::wstring aName = Locale::Convert::toWString(anAttr->Get().ToExtString());
- if(!aName.empty()) {
+ if (!aName.empty()) {
std::shared_ptr<Model_Document> aDoc =
std::dynamic_pointer_cast<Model_Document>(document());
aDoc->addNamingName(aBuilder->NamedShape()->Label(), aName);
storeExternalReference(anOriginalLabel, aBuilder->NamedShape()->Label());
}
- if(!aBuilder->NamedShape()->IsEmpty()) {
+ if (!aBuilder->NamedShape()->IsEmpty()) {
Handle(TDataStd_Name) anAttr;
- if(aBuilder->NamedShape()->Label().FindAttribute(TDataStd_Name::GetID(), anAttr)) {
+ if (aBuilder->NamedShape()->Label().FindAttribute(TDataStd_Name::GetID(), anAttr)) {
std::wstring aName = Locale::Convert::toWString(anAttr->Get().ToExtString());
- if(!aName.empty()) {
+ if (!aName.empty()) {
std::shared_ptr<Model_Document> aDoc =
std::dynamic_pointer_cast<Model_Document>(document());
aDoc->addNamingName(aBuilder->NamedShape()->Label(), aName);
if (anIndexTags.index == 2) {
buildName(anIndexTags.tags.front(), theName + "_1");
}
- }
- else {
+ } else {
IndexTags anIndexTags;
anIndexTags.index = 1;
anIndexTags.tags.push_back(myFreePrimitiveTag);
void Model_BodyBuilder::loadNextLevels(GeomShapePtr theShape,
const std::string& theName)
{
- if(theShape->isNull()) return;
+ if (theShape->isNull()) return;
TopoDS_Shape aShape = theShape->impl<TopoDS_Shape>();
std::string aName;
if (aShape.ShapeType() == TopAbs_SOLID) {
TopTools_ListIteratorOfListOfShape anIter(aLL);
const TopoDS_Face& aFace = TopoDS::Face(anIter.Value());
anIter.Next();
- if(aFace.IsEqual(anIter.Value())) {
+ if (aFace.IsEqual(anIter.Value())) {
builder(myFreePrimitiveTag)->Generated(anEdgeAndNeighbourFaces.FindKey(i));
TCollection_AsciiString aStr(myFreePrimitiveTag - PRIMITIVES_START_TAG + 1);
aName = theName + "_" + aStr.ToCString();
loadNextLevels(itrShape, theName);
}
TopTools_ListOfShape aList;
- if(findAmbiguities(aShape, aList)) {
+ if (findAmbiguities(aShape, aList)) {
TopTools_ListIteratorOfListOfShape it(aList);
for (; it.More(); it.Next(), ++myFreePrimitiveTag) {
builder(myFreePrimitiveTag)->Generated(it.Value());
theResult->data()->setName(L"");
} else {
std::wstringstream aName;
- if( theNameShape != L"" ){
+ if ( theNameShape != L"" ){
aName << theNameShape;
- }else{
+ } else {
aName << aNewName;
// if there are several results (issue #899: any number of result),
// add unique prefix starting from second
/// Creates a body result
std::shared_ptr<ModelAPI_ResultBody> createBody(
const std::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex = 0,
- const std::wstring& theNameShape = L"");
+ const std::wstring& theNameShape = L"");
/// Creates a part result
std::shared_ptr<ModelAPI_ResultPart> createPart(
const std::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex = 0);
//! Initializes the data fields of the feature
void initData(ObjectPtr theObj, TDF_Label theLab, const int theTag);
- //! Allows to store the result in the data tree of the document
+ //! Allows to store the result in the data tree of the document
//! (attaches 'data' of result to tree)
void storeResult(std::shared_ptr<ModelAPI_Data> theFeatureData,
std::shared_ptr<ModelAPI_Result> theResult,
void Model_ResultBody::addShapeColor( const std::wstring& theName,std::vector<int>& color) {
- if( myColorsShape.find(theName) == myColorsShape.end())
+ if (myColorsShape.find(theName) == myColorsShape.end())
myColorsShape[ theName ] = color;
}
std::wstring Model_ResultBody::addShapeName(std::shared_ptr<GeomAPI_Shape> theshape,
const std::wstring& theName ){
- int indice = 1;
- std::wstringstream aName;
- aName << theName;
- while(myNamesShape.find(aName.str()) != myNamesShape.end() ){
- aName.str(L"");
- aName << theName << L"__" << indice;
- indice++;
- }
- myNamesShape[ aName.str() ] = theshape;
+ int indice = 1;
+ std::wstringstream aName;
+ aName << theName;
+ while(myNamesShape.find(aName.str()) != myNamesShape.end() ){
+ aName.str(L"");
+ aName << theName << L"__" << indice;
+ indice++;
+ }
+ myNamesShape[ aName.str() ] = theshape;
- return aName.str();
+ return aName.str();
}
std::wstring Model_ResultBody::findShapeName(std::shared_ptr<GeomAPI_Shape> theshape){
- TopoDS_Shape aShape = theshape->impl<TopoDS_Shape>();
- for (std::map< std::wstring, std::shared_ptr<GeomAPI_Shape> >::iterator it =
- myNamesShape.begin();
- it != myNamesShape.end();
- ++it)
- {
- TopoDS_Shape curSelectedShape = (*it).second->impl<TopoDS_Shape>();
- if( (aShape.IsSame(curSelectedShape))) {
- return (*it).first;
- }
- }
- return L"material not found" ;
+ TopoDS_Shape aShape = theshape->impl<TopoDS_Shape>();
+ for (std::map< std::wstring, std::shared_ptr<GeomAPI_Shape> >::iterator it =
+ myNamesShape.begin();
+ it != myNamesShape.end();
+ ++it)
+ {
+ TopoDS_Shape curSelectedShape = (*it).second->impl<TopoDS_Shape>();
+ if ((aShape.IsSame(curSelectedShape))) {
+ return (*it).first;
+ }
+ }
+ return L"material not found" ;
}
-
void Model_ResultBody::setShapeName(
std::map< std::wstring, std::shared_ptr<GeomAPI_Shape> > &theshapename,
std::map< std::wstring, std::vector<int>> & theColorsShape)
{
- myNamesShape = theshapename;
- myColorsShape = theColorsShape;
+ myNamesShape = theshapename;
+ myColorsShape = theColorsShape;
}
void Model_ResultBody::clearShapeNameAndColor(){
++it)
{
TopoDS_Shape curSelectedShape = (*it).second->impl<TopoDS_Shape>();
- if( !(aShapesIter.Value().IsSame(curSelectedShape))) continue;
+ if (!(aShapesIter.Value().IsSame(curSelectedShape))) continue;
thenameshape = (*it).first;
break;
}
//finf color read
std::map< std::wstring, std::vector<int>>::iterator itColor =
myColorsShape.find(thenameshape);
- if(itColor != myColorsShape.end()){
+ if (itColor != myColorsShape.end()){
ModelAPI_Tools::setColor(aSub,(*itColor).second);
}
aSub->setShapeName(myNamesShape,myColorsShape);
/// Makes a body on the given feature
Model_ResultBody();
-/// Updates the sub-bodies if shape of this object is composite-solid
+ /// Updates the sub-bodies if shape of this object is composite-solid
void updateSubs(const std::shared_ptr<GeomAPI_Shape>& theThisShape,
const bool theShapeChanged = true);
const GeomShapePtr& theThisShape, const std::list<GeomShapePtr>& theOlds,
const std::shared_ptr<GeomAlgoAPI_MakeShape> theMakeShape, const bool isGenerated);
- // Checks the state of children and parents to send events of creation/erase when needed
+ /// Checks the state of children and parents to send events of creation/erase when needed
void updateConcealment();
/// Adds to theOldForSub only old shapes that where used for theSub creation
friend class Model_Objects;
- // Add shape Name for read shape in step file
+ /// Add shape Name for read shape in step file
std::wstring addShapeName(std::shared_ptr<GeomAPI_Shape>,const std::wstring& theName) override;
- // Add color for shape Name read shape in step file
+ /// Add color for shape Name read shape in step file
void addShapeColor( const std::wstring& theName,std::vector<int>& color) override;
- // Set the map of name and color read shape in step file
+ /// Set the map of name and color read shape in step file
void setShapeName(std::map< std::wstring,
std::shared_ptr<GeomAPI_Shape> > &theshapename,
std::map< std::wstring,
std::vector<int>> & theColorsShape) override;
- // find the name of shapp read in step file
+ /// find the name of shapp read in step file
std::wstring findShapeName(std::shared_ptr<GeomAPI_Shape> theshape) override;
- // Clear the map of name and color read shape in step file
+ /// Clear the map of name and color read shape in step file
void clearShapeNameAndColor() override;
- // map with the name read in step file and shape
+ /// map with the name read in step file and shape
std::map< std::wstring, std::shared_ptr<GeomAPI_Shape> > myNamesShape;
- // map with the name contruct and color read
+ /// map with the name contruct and color read
std::map< std::wstring, std::vector<int>> myColorsShape;
};
/// Cleans cash related to the already stored elements
MODELAPI_EXPORT virtual void cleanCash() = 0;
-
- // Add shape Name for read shape in step file
- MODELAPI_EXPORT virtual std::wstring addShapeName(std::shared_ptr<GeomAPI_Shape>,const std::wstring& theName) = 0;
- // Add color for shape Name read shape in step file
- MODELAPI_EXPORT virtual void addShapeColor(const std::wstring& theName,std::vector<int>& color) = 0;
- // Set the map of name and color read shape in step file
- MODELAPI_EXPORT virtual void setShapeName(std::map< std::wstring, std::shared_ptr<GeomAPI_Shape> > &theshapename,
- std::map< std::wstring, std::vector<int>> & theColorsShape) = 0;
- // Clear the map of name and color read shape in step file
+
+ /// Add shape Name for read shape in step file
+ MODELAPI_EXPORT virtual std::wstring addShapeName
+ (std::shared_ptr<GeomAPI_Shape>,const std::wstring& theName) = 0;
+ /// Add color for shape Name read shape in step file
+ MODELAPI_EXPORT virtual void addShapeColor
+ (const std::wstring& theName,std::vector<int>& color) = 0;
+ /// Set the map of name and color read shape in step file
+ MODELAPI_EXPORT virtual void setShapeName
+ (std::map< std::wstring, std::shared_ptr<GeomAPI_Shape> > &theshapename,
+ std::map< std::wstring, std::vector<int>> & theColorsShape) = 0;
+ /// Clear the map of name and color read shape in step file
MODELAPI_EXPORT virtual void clearShapeNameAndColor() = 0;
- // find the name of shapp read in step file
+ /// find the name of shapp read in step file
MODELAPI_EXPORT virtual std::wstring findShapeName(std::shared_ptr<GeomAPI_Shape> theshape) = 0;
/// Default constructor accessible only from Model_Objects
MODELAPI_EXPORT ModelAPI_ResultBody();
-
-
};
//! Pointer on feature object
"""Package for Exchange plugin for the Parametric Geometry API of the Modeler.
"""
-from ExchangeAPI import addImport, addImportStep, exportToFile, exportToXAO, exportToSTL
+from ExchangeAPI import addImport, addImportSTEP, exportToFile, exportToXAO, exportToSTL
from ExchangeAPI import exportPart, importPart
from .tools import *