import math
from tempfile import TemporaryDirectory
-import GEOM
-
from ModelAPI import *
from salome.shaper import model
-from salome.geom import geomBuilder
-
from GeomAPI import GeomAPI_Shape
from GeomAlgoAPI import *
__updated__ = "2015-05-22"
salome.salome_init(1)
-geompy = geomBuilder.New()
#=========================================================================
# Help functions
ModelAPI_AttributeSelectionList::typeId());
data()->addAttribute(ExchangePlugin_ExportFeature::STL_FILE_PATH_ID(),
ModelAPI_AttributeString::typeId());
- data()->addAttribute(ExchangePlugin_ExportFeature::STL_OBJECT_SELECTED(),
+ data()->addAttribute(ExchangePlugin_ExportFeature::STL_OBJECT_SELECTED(),
ModelAPI_AttributeSelection::typeId());
data()->addAttribute(ExchangePlugin_ExportFeature::STL_DEFLECTION_TYPE(),
ModelAPI_AttributeString::typeId());
- data()->addAttribute(ExchangePlugin_ExportFeature::STL_RELATIVE(),
+ data()->addAttribute(ExchangePlugin_ExportFeature::STL_RELATIVE(),
ModelAPI_AttributeDouble::typeId());
-
+
double defelection = Config_PropManager::real("Visualization", "body_deflection");
real(ExchangePlugin_ExportFeature::STL_RELATIVE())->setValue(defelection);
- data()->addAttribute(ExchangePlugin_ExportFeature::STL_ABSOLUTE(),
+ data()->addAttribute(ExchangePlugin_ExportFeature::STL_ABSOLUTE(),
ModelAPI_AttributeDouble::typeId());
data()->addAttribute(ExchangePlugin_ExportFeature::STL_FILE_TYPE(),
ModelAPI_AttributeString::typeId());
if (string(STL_FILE_TYPE())->value() == STL_FILE_TYPE_ASCII()) {
anIsASCII = true;
- }
+ }
// Perform the export
std::string anError;
bool aResult = false;
"STL",
aShape,
aValue,
- anIsRelative,
+ anIsRelative,
anIsASCII,
anError);
/// \param theID identifier of changed attribute
EXCHANGEPLUGIN_EXPORT virtual void attributeChanged(const std::string& theID);
- EXCHANGEPLUGIN_EXPORT
- void updatePart(AttributeStringArrayPtr &aPartsAttr, AttributeIntegerPtr &aTargetAttr);
-
/// Computes or recomputes the results
EXCHANGEPLUGIN_EXPORT virtual void execute();
/// Reimplemented from ModelAPI_Feature::isPreviewNeeded(). Returns false.
EXCHANGEPLUGIN_EXPORT virtual bool isPreviewNeeded() const { return false; }
+
+ private:
+
+ EXCHANGEPLUGIN_EXPORT
+ void updatePart(AttributeStringArrayPtr &aPartsAttr, AttributeIntegerPtr &aTargetAttr);
};
#endif /* IMPORT_IMPORTFEATURE_H_ */
#include <ExchangePlugin_Tools.h>
-#include <TopExp_Explorer.hxx>
-#include <OSD_Exception.hxx>
ExchangePlugin_ImportFeature::ExchangePlugin_ImportFeature()
std::string anError;
std::shared_ptr<GeomAPI_Shape> aGeomShape;
- std::map< std::wstring, std::list<std::wstring>> theMaterialShape;
+ std::map< std::wstring,std::list<std::wstring>> theMaterialShape;
std::string anObjectName = GeomAlgoAPI_Tools::File_Tools::name(theFileName);
data()->setName(Locale::Convert::toWString(anObjectName));
bool anScalInterUnits =
boolean(ExchangePlugin_ImportFeature::STEP_SCALE_INTER_UNITS_ID())->value();
- try{
+ // Process groups/fields
+ std::shared_ptr<ModelAPI_AttributeRefList> aRefListOfGroups =
+ std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(data()->attribute(FEATURES_ID()));
- aResult->clearShapeNameAndColor();
- // Process groups/fields
- std::shared_ptr<ModelAPI_AttributeRefList> aRefListOfGroups =
- std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(data()->attribute(FEATURES_ID()));
-
- // Remove previous groups/fields stored in RefList
- std::list<ObjectPtr> anGroupList = aRefListOfGroups->list();
- std::list<ObjectPtr>::iterator anGroupIt = anGroupList.begin();
- for (; anGroupIt != anGroupList.end(); ++anGroupIt) {
- std::shared_ptr<ModelAPI_Feature> aFeature = ModelAPI_Feature::feature(*anGroupIt);
- if (aFeature)
- document()->removeFeature(aFeature);
- }
-
- aGeomShape = STEPImportAttributs(theFileName, aResult, anScalInterUnits,
- anMaterialsGroupSelected, anColorGroupSelected,
- theMaterialShape,anError);
-
- }
- catch (OSD_Exception& e) {
- //Try to load STEP file without colors...
- aGeomShape = STEPImport(theFileName, anExtension,anScalInterUnits,anError);
+ // Remove previous groups/fields stored in RefList
+ std::list<ObjectPtr> anGroupList = aRefListOfGroups->list();
+ std::list<ObjectPtr>::iterator anGroupIt = anGroupList.begin();
+ for (; anGroupIt != anGroupList.end(); ++anGroupIt) {
+ std::shared_ptr<ModelAPI_Feature> aFeature = ModelAPI_Feature::feature(*anGroupIt);
+ if (aFeature)
+ document()->removeFeature(aFeature);
}
+
+ aGeomShape = STEPImportAttributs(theFileName, aResult, anScalInterUnits,
+ anMaterialsGroupSelected, anColorGroupSelected,
+ theMaterialShape,anError);
} else if (anExtension == "IGES" || anExtension == "IGS") {
aGeomShape = IGESImport(theFileName, anExtension, anError);
} else {
}
setResult(aResult);
+ aResult->clearShapeNameAndColor();
}
{
std::vector<int> aColor;
int anIndice = 1;
- std::list< std::vector<int> > aColorsRead;
+ std::list<std::vector<int>> aColorsRead;
ModelAPI_Tools::getColor(theResultBody, aColor);
if (!aColor.empty() ){
std::wstringstream aColorName;
aColorName <<L"Color_"<< anIndice;
- setColorGroup( theResultBody, aColor, aColorName.str());
+ setColorGroup(theResultBody, aColor, aColorName.str());
anIndice++;
aColorsRead.push_back(aColor);
}
if (!aColor.empty() ){
if (aColor == theColor ) {
GeomShapePtr aShape = theResultBody->shape();
- aSelectionList->setSelectionType(aShape->shapeTypeStr() );
+ aSelectionList->setSelectionType(aShape->shapeTypeStr());
aSelectionList->append(theResultBody,aShape);
}
}
if (!aColor.empty() ){
if (aRes->get() && aColor == theColor ) {
- aSelectionList->setSelectionType(aShape->shapeTypeStr() );
+ aSelectionList->setSelectionType(aShape->shapeTypeStr());
aSelectionList->append(theResultBody,aShape);
}
}
ModelAPI_Tools::setColor(aGroupFeature->lastResult(),theColor);
- if (aSelectionList->size() == 0 ){
+ if (aSelectionList->size() == 0) {
document()->removeFeature(aGroupFeature);
}
}
void ExchangePlugin_ImportFeature::setMaterielGroup(
std::shared_ptr<ModelAPI_ResultBody> theResultBody,
- std::map< std::wstring,std::list<std::wstring>> &theMaterialShape)
+ std::map<std::wstring,std::list<std::wstring>> &theMaterialShape)
{
std::map< std::wstring, std::list<std::wstring>>::iterator anIt;
- for( anIt = theMaterialShape.begin(); anIt != theMaterialShape.end(); ++anIt) {
+ for (anIt = theMaterialShape.begin(); anIt != theMaterialShape.end(); ++anIt) {
std::shared_ptr<ModelAPI_Feature> aGroupFeature = addFeature("Group");
// group name
// fill selection
AttributeSelectionListPtr aSelectionList = aGroupFeature->selectionList("group_list");
- GeomShapePtr aShape = theResultBody->shape();
std::list<ResultPtr> allRes;
ModelAPI_Tools::allSubs(theResultBody, allRes);
- for(std::list<ResultPtr>::iterator aRes = allRes.begin(); aRes != allRes.end(); ++aRes) {
+ for (std::list<ResultPtr>::iterator aRes = allRes.begin(); aRes != allRes.end(); ++aRes) {
GeomShapePtr aShape = (*aRes)->shape();
- for(std::list<std::wstring>::iterator aResMat = anIt->second.begin();
+ for (std::list<std::wstring>::iterator aResMat = anIt->second.begin();
aResMat != anIt->second.end(); ++aResMat) {
if (aRes->get() && ((*aRes)->data()->name() == (*aResMat)))
{
aSelectionList->append(theResultBody,aShape);
- aSelectionList->setSelectionType(aShape->shapeTypeStr() );
+ aSelectionList->setSelectionType(aShape->shapeTypeStr());
break;
}
}
<translation>Mettre àl'échelle du système international d'unités</translation>
</message>
</context>
+ <context>
<name>Import:step_materials</name>
<message>
<source>Materials</source>
</message>
</context>
<context>
- <name>Import:step_materials</name>
+ <name>Import:step_colors</name>
<message>
<source>Colors</source>
<translation>Couleurs</translation>
<source>Import a file</source>
<translation>Importer un fichier</translation>
</message>
- </context>
- <message>
+ <message>
<source>Create groups from</source>
<translation>créer des groupes à partir</translation>
</message>
+ </context>
<context>
<name>ImportMacro:target_part</name>
<message>
#include <TopoDS_Iterator.hxx>
#include <Standard_ErrorHandler.hxx> // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC
+#include <OSD_Exception.hxx>
+
+//=================================================================================================
+bool readUnits(const STEPControl_Reader& aReader,
+ const bool theScalInterUnits,
+ std::string& theError)
+{
+ // Regard or not the model units
+ if (!theScalInterUnits) {
+ // set UnitFlag to units from file
+ TColStd_SequenceOfAsciiString anUnitLengthNames;
+ TColStd_SequenceOfAsciiString anUnitAngleNames;
+ TColStd_SequenceOfAsciiString anUnitSolidAngleNames;
+ aReader.FileUnits(anUnitLengthNames, anUnitAngleNames, anUnitSolidAngleNames);
+ if (anUnitLengthNames.Length() > 0) {
+ TCollection_AsciiString aLenUnits = anUnitLengthNames.First();
+ if (aLenUnits == "millimetre")
+ Interface_Static::SetCVal("xstep.cascade.unit", "MM");
+ else if (aLenUnits == "centimetre")
+ Interface_Static::SetCVal("xstep.cascade.unit", "CM");
+ else if (aLenUnits == "metre" || aLenUnits.IsEmpty())
+ Interface_Static::SetCVal("xstep.cascade.unit", "M");
+ else if (aLenUnits == "INCH")
+ Interface_Static::SetCVal("xstep.cascade.unit", "INCH");
+ else {
+ theError = "The file contains not supported units.";
+ return false;
+ }
+ // TODO (for other units than mm, cm, m or inch)
+ //else if (aLenUnits == "")
+ // Interface_Static::SetCVal("xstep.cascade.unit", "???");
+ }
+ }
+ else {
+ //cout<<"need re-scale a model"<<endl;
+ // set UnitFlag to 'meter'
+ Interface_Static::SetCVal("xstep.cascade.unit","M");
+ }
+ return true;
+}
//==================================================================================================
IFSelect_ReturnStatus status = aReader.ReadFile(theFileName.c_str());
if (status == IFSelect_RetDone) {
-
// Regard or not the model units
- if (!theScalInterUnits) {
- // set UnitFlag to units from file
- TColStd_SequenceOfAsciiString anUnitLengthNames;
- TColStd_SequenceOfAsciiString anUnitAngleNames;
- TColStd_SequenceOfAsciiString anUnitSolidAngleNames;
- aReader.FileUnits(anUnitLengthNames, anUnitAngleNames, anUnitSolidAngleNames);
- if (anUnitLengthNames.Length() > 0) {
- TCollection_AsciiString aLenUnits = anUnitLengthNames.First();
- if (aLenUnits == "millimetre")
- Interface_Static::SetCVal("xstep.cascade.unit", "MM");
- else if (aLenUnits == "centimetre")
- Interface_Static::SetCVal("xstep.cascade.unit", "CM");
- else if (aLenUnits == "metre" || aLenUnits.IsEmpty())
- Interface_Static::SetCVal("xstep.cascade.unit", "M");
- else if (aLenUnits == "INCH")
- Interface_Static::SetCVal("xstep.cascade.unit", "INCH");
- else {
- theError = "The file contains not supported units.";
- std::shared_ptr<GeomAPI_Shape> aGeomShape(new GeomAPI_Shape);
- aGeomShape->setImpl(new TopoDS_Shape(aResShape));
- return aGeomShape;
- }
- // TODO (for other units than mm, cm, m or inch)
- //else if (aLenUnits == "")
- // Interface_Static::SetCVal("xstep.cascade.unit", "???");
- }
- }
- else {
- //cout<<"need re-scale a model"<<endl;
- // set UnitFlag to 'meter'
- Interface_Static::SetCVal("xstep.cascade.unit","M");
+ if( !readUnits(aReader,theScalInterUnits,theError)) {
+ std::shared_ptr<GeomAPI_Shape> aGeomShape(new GeomAPI_Shape);
+ aGeomShape->setImpl(new TopoDS_Shape());
+ return aGeomShape;
}
Standard_Boolean failsonly = Standard_False;
std::string& theError)
{
- STEPControl_Reader aReader;
- std::shared_ptr<GeomAPI_Shape> aGeomShape(new GeomAPI_Shape);
+ try{
- Interface_Static::SetCVal("xstep.cascade.unit","M");
- Interface_Static::SetIVal("read.step.ideas", 1);
- Interface_Static::SetIVal("read.step.nonmanifold", 1);
+ STEPControl_Reader aReader;
+ std::shared_ptr<GeomAPI_Shape> aGeomShape(new GeomAPI_Shape);
- try {
- OCC_CATCH_SIGNALS;
+ Interface_Static::SetCVal("xstep.cascade.unit","M");
+ Interface_Static::SetIVal("read.step.ideas", 1);
+ Interface_Static::SetIVal("read.step.nonmanifold", 1);
- IFSelect_ReturnStatus status = aReader.ReadFile(theFileName.c_str());
+ try {
+ OCC_CATCH_SIGNALS;
- if (status == IFSelect_RetDone) {
+ IFSelect_ReturnStatus status = aReader.ReadFile(theFileName.c_str());
- // Regard or not the model units
- if (!theScalInterUnits) {
- // set UnitFlag to units from file
- TColStd_SequenceOfAsciiString anUnitLengthNames;
- TColStd_SequenceOfAsciiString anUnitAngleNames;
- TColStd_SequenceOfAsciiString anUnitSolidAngleNames;
- aReader.FileUnits(anUnitLengthNames, anUnitAngleNames, anUnitSolidAngleNames);
- if (anUnitLengthNames.Length() > 0) {
- TCollection_AsciiString aLenUnits = anUnitLengthNames.First();
- if (aLenUnits == "millimetre")
- Interface_Static::SetCVal("xstep.cascade.unit", "MM");
- else if (aLenUnits == "centimetre")
- Interface_Static::SetCVal("xstep.cascade.unit", "CM");
- else if (aLenUnits == "metre" || aLenUnits.IsEmpty())
- Interface_Static::SetCVal("xstep.cascade.unit", "M");
- else if (aLenUnits == "INCH")
- Interface_Static::SetCVal("xstep.cascade.unit", "INCH");
- else {
- theError = "The file contains not supported units.";
+ if (status == IFSelect_RetDone) {
+ // Regard or not the model units
+ if( !readUnits(aReader,theScalInterUnits,theError)) {
aGeomShape->setImpl(new TopoDS_Shape());
return aGeomShape;
- }
- // TODO (for other units than mm, cm, m or inch)
- //else if (aLenUnits == "")
- // Interface_Static::SetCVal("xstep.cascade.unit", "???");
}
}
- else {
- //cout<<"need re-scale a model"<<endl;
- // set UnitFlag to 'meter'
- Interface_Static::SetCVal("xstep.cascade.unit","M");
- }
}
- }
- catch (Standard_Failure const& anException) {
- theError = anException.GetMessageString();
- aGeomShape->setImpl(new TopoDS_Shape());
- return aGeomShape;
- }
+ catch (Standard_Failure const& anException) {
+ theError = anException.GetMessageString();
+ aGeomShape->setImpl(new TopoDS_Shape());
+ return aGeomShape;
+ }
- STEPCAFControl_Reader aCafreader;
- aCafreader.SetColorMode(true);
- aCafreader.SetNameMode(true);
- aCafreader.SetMatMode(true);
+ STEPCAFControl_Reader aCafreader;
+ aCafreader.SetColorMode(true);
+ aCafreader.SetNameMode(true);
+ aCafreader.SetMatMode(true);
- if(aCafreader.ReadFile(theFileName.c_str()) != IFSelect_RetDone) {
- theError = "Wrong format of the imported file. Can't import file.";
- std::shared_ptr<GeomAPI_Shape> aGeomShape(new GeomAPI_Shape);
- aGeomShape->setImpl(new TopoDS_Shape());
- return aGeomShape;
- }
+ if(aCafreader.ReadFile(theFileName.c_str()) != IFSelect_RetDone) {
+ theError = "Wrong format of the imported file. Can't import file.";
+ std::shared_ptr<GeomAPI_Shape> aGeomShape(new GeomAPI_Shape);
+ aGeomShape->setImpl(new TopoDS_Shape());
+ return aGeomShape;
+ }
- return readAttributes(aCafreader,
- theResultBody,
- theMaterials,
- theMaterialShape,
- theError);
+ return readAttributes(aCafreader,
+ theResultBody,
+ theMaterials,
+ theMaterialShape,
+ theError);
+ }
+ catch (OSD_Exception& e) {
+ //Try to load STEP file without colors...
+ return STEPImport(theFileName,"",theScalInterUnits,theError);
+ }
}
\ No newline at end of file
Handle(StepRepr_ProductDefinitionShape)::DownCast(theEnti);
Handle(StepBasic_ProductDefinition) aProdDef;
- if (aPDS.IsNull() == Standard_False) {
+ if (!aPDS.IsNull()) {
// Product Definition Shape ==> Product Definition
aProdDef = aPDS->Definition().ProductDefinition();
}
- if (aProdDef.IsNull() == Standard_False) {
+ if (!aProdDef.IsNull()) {
// Product Definition ==> Property Definition
const Interface_Graph &aGraph = theTP->Graph();
Interface_EntityIterator aSubs = aGraph.Sharings(aProdDef);
Handle(StepRepr_PropertyDefinition) aPropD =
Handle(StepRepr_PropertyDefinition)::DownCast(aSubs.Value());
- if (aPropD.IsNull() == Standard_False) {
+ if (!aPropD.IsNull()) {
// Property Definition ==> Representation.
Interface_EntityIterator aSubs1 = aGraph.Sharings(aPropD);
Handle(StepRepr_PropertyDefinitionRepresentation)::
DownCast(aSubs1.Value());
- if (aPDR.IsNull() == Standard_False) {
+ if (!aPDR.IsNull()) {
// Property Definition ==> Material Name.
Handle(StepRepr_Representation) aRepr = aPDR->UsedRepresentation();
- if (aRepr.IsNull() == Standard_False) {
+ if (!aRepr.IsNull()) {
Standard_Integer anIr;
for(anIr = 1; anIr <= aRepr->NbItems(); anIr++) {
Handle(StepRepr_DescriptiveRepresentationItem) aDRI =
Handle(StepRepr_DescriptiveRepresentationItem)::DownCast(aRI);
- if (aDRI.IsNull() == Standard_False) {
+ if (!aDRI.IsNull()) {
// Get shape from Product Definition
Handle(TCollection_HAsciiString) aMatName = aDRI->Name();
- if (aMatName.IsNull() == Standard_False) {
+ if (!aMatName.IsNull()) {
TCollection_ExtendedString
aMatNameExt (aMatName->ToCString());
const std::string& /*theFormatName*/,
const std::shared_ptr<GeomAPI_Shape>& theShape,
const double aDeflection,
- const bool anIsRelative,
+ const bool anIsRelative,
const bool anIsASCII,
std::string& theError)
{
const std::string& /*theFormatName*/,
const std::shared_ptr<GeomAPI_Shape>& theShape,
const double aDeflection,
- const bool anIsRelative,
+ const bool anIsRelative,
const bool anIsASCII,
std::string& theError);
SET(PROJECT_LIBRARIES
Config
GeomAPI
- ${OpenCASCADE_ApplicationFramework_LIBRARIES}
+ Locale
)
SET(CMAKE_SWIG_FLAGS -threads -w325,321,362,383,302,403,451,473)
ADD_DEFINITIONS(-DMODELAPI_EXPORTS)
${PROJECT_SOURCE_DIR}/src/GeomAPI
${PROJECT_SOURCE_DIR}/src/GeomAlgoAPI
${PROJECT_SOURCE_DIR}/src/Locale
- ${OpenCASCADE_INCLUDE_DIR}
- ${OpenCASCADE_DataExchange_LIBRARIES}
- ${OpenCASCADE_ModelingAlgorithms_LIBRARIES}
- ${OpenCASCADE_ApplicationFramework_LIBRARIES}
)