* \param theIsIgnoreUnits If True, file length units will be ignored (set to 'meter')
* and result model will be scaled, if its units are not meters.
* If False (default), file length units will be taken into account.
+ * \param IsCreateAssemblies If True, for each assembly compound is created
+ * in the result. If False Compounds that contain a
+ * single shape are eliminated from the result.
* \return List of GEOM_Objects, containing the created shape and propagation groups.
*/
GEOM::ListOfGO ImportSTEP( in string theFileName,
- in boolean theIsIgnoreUnits );
+ in boolean theIsIgnoreUnits,
+ in boolean IsCreateAssemblies);
/*!
* \brief Read a value of parameter from a file, containing a shape.
beginService( " GEOM_Superv_i::ImportSTEP" );
MESSAGE("GEOM_Superv_i::ImportSTEP");
getSTEPPluginOp();
- GEOM::ListOfGO* aSeq = mySTEPOp->ImportSTEP(theFileName, theIsIgnoreUnits );
+ GEOM::ListOfGO* aSeq = mySTEPOp->ImportSTEP(theFileName, theIsIgnoreUnits, false );
GEOM::GEOM_Object_ptr anObj;
if (aSeq->length() > 0) {
# @param theIsIgnoreUnits If True, file length units will be ignored (set to 'meter')
# and result model will be scaled, if its units are not meters.
# If False (default), file length units will be taken into account.
+# @param IsCreateAssemblies If True, for each assembly compound is created in
+# the result. If False Compounds that contain a single shape
+# are eliminated from the result.
# @param theName Object name; when specified, this parameter is used
# for result publication in the study. Otherwise, if automatic
# publication is switched on, default value is used for result name.
#
# @ref swig_Import_Export "Example"
# @ingroup l2_import_export
-def ImportSTEP(self, theFileName, theIsIgnoreUnits = False, theName=None):
+def ImportSTEP(self, theFileName, theIsIgnoreUnits = False,
+ IsCreateAssemblies = False, theName=None):
"""
Import a shape from the STEP file with given name.
ignoreUnits If True, file length units will be ignored (set to 'meter')
and result model will be scaled, if its units are not meters.
If False (default), file length units will be taken into account.
+ IsCreateAssemblies If True, for each assembly compound is created in
+ the result. If False Compounds that contain a single shape
+ are eliminated from the result.
theName Object name; when specified, this parameter is used
for result publication in the study. Otherwise, if automatic
publication is switched on, default value is used for result name.
anOp = GetSTEPPluginOperations(self)
anIsIgnoreUnits = theIsIgnoreUnits
+ anIsCreateAssemblies = IsCreateAssemblies;
aName = theName
if isinstance( theIsIgnoreUnits, basestring ):
anIsIgnoreUnits = False
aName = theIsIgnoreUnits
pass
+ elif isinstance( IsCreateAssemblies, basestring ):
+ anIsCreateAssemblies = False
+ aName = IsCreateAssemblies
+ pass
- aListObj = anOp.ImportSTEP(theFileName,anIsIgnoreUnits)
+ aListObj = anOp.ImportSTEP(theFileName,anIsIgnoreUnits,anIsCreateAssemblies)
RaiseIfFailed("ImportSTEP", anOp)
aNbObj = len(aListObj)
if aNbObj > 0:
STEPPlugin_IExport.hxx
STEPPlugin_IImport.hxx
STEPPlugin_ImportDriver.hxx
+ STEPPlugin_ImportDlg.h
STEPPlugin_ExportDlg.h
STEPPlugin_ExportDriver.hxx
STEPPlugin_IECallBack.hxx
SET(_moc_HEADERS
STEPPlugin_GUI.h
STEPPlugin_ExportDlg.h
+ STEPPlugin_ImportDlg.h
)
ENDIF()
SET(STEPPluginGUI_SOURCES
STEPPlugin_GUI.cxx
STEPPlugin_ExportDlg.cxx
+ STEPPlugin_ImportDlg.cxx
${_moc_SOURCES}
)
ENDIF()
#include "GEOM_Displayer.h"
#include "GEOM_GenericObjPtr.h"
#include "STEPPlugin_ExportDlg.h"
+#include "STEPPlugin_ImportDlg.h"
#include <SALOMEconfig.h>
#include CORBA_SERVER_HEADER(STEPPlugin)
STEPOpPtr stepOp = GEOM::ISTEPOperations::_narrow( op );
if ( stepOp.isNull() ) return false;
- QStringList fileNames = app->getOpenFileNames( SUIT_FileDlg::getLastVisitedPath().isEmpty() ? QDir::currentPath() : QString(""),
- tr( "STEP_FILES" ),
- tr( "IMPORT_TITLE" ),
- parent );
+ bool isCreateAssemblies = true;
+ QStringList fileNames = STEPPlugin_ImportDlg::getOpenFileNames
+ (SUIT_FileDlg::getLastVisitedPath().isEmpty() ? QDir::currentPath() : QString(""),
+ tr("STEP_FILES"), tr("IMPORT_TITLE"), parent, isCreateAssemblies);
+
if ( fileNames.count() > 0 )
{
QStringList entryList;
}
}
- GEOM::ListOfGO_var result = stepOp->ImportSTEP( fileName.toUtf8().constData(), ignoreUnits );
+ GEOM::ListOfGO_var result = stepOp->ImportSTEP
+ (fileName.toUtf8().constData(), ignoreUnits, isCreateAssemblies);
if ( result->length() > 0 && stepOp->IsDone() )
{
GEOM::GEOM_Object_var main = result[0];
{
STEPPlugin_IOperations* aPluginOperations = STEPPlugin_OperationsCreator::get( GetEngine(), theDocId );
bool anIsIgnoreUnits = ( theFormatName == "STEP_SCALE" ) ? true : false;
- return aPluginOperations->ImportSTEP( theFileName, anIsIgnoreUnits );
+ return aPluginOperations->ImportSTEP( theFileName, anIsIgnoreUnits, false );
}
//=============================================================================
#include "GEOM_Function.hxx"
-#define IMPORTSTEP_ARG_FILENAME 1
-#define IMPORTSTEP_ARG_IGNORE_UNITS 2
+#define IMPORTSTEP_ARG_FILENAME 1
+#define IMPORTSTEP_ARG_IGNORE_UNITS 2
+#define IMPORTSTEP_ARG_CREATE_ASSEMBLIES 3
class STEPPlugin_IImport
{
bool GetIsIgnoreUnits()
{ return bool( _func->GetInteger( IMPORTSTEP_ARG_IGNORE_UNITS ) ); }
+ void SetIsCreateAssemblies( bool IsCreateAssemblies )
+ { _func->SetInteger
+ ( IMPORTSTEP_ARG_CREATE_ASSEMBLIES, IsCreateAssemblies ? 1 : 0 ); }
+ bool GetIsCreateAssemblies()
+ { return ( _func->GetInteger( IMPORTSTEP_ARG_CREATE_ASSEMBLIES ) != 0 ); }
+
private:
Handle(GEOM_Function) _func;
};
*/
//=============================================================================
Handle(TColStd_HSequenceOfTransient)
-STEPPlugin_IOperations::ImportSTEP( const TCollection_AsciiString& theFileName,
- const bool theIsIgnoreUnits )
+STEPPlugin_IOperations::ImportSTEP(const TCollection_AsciiString& theFileName,
+ const bool theIsIgnoreUnits,
+ const bool IsCreateAssemblies)
{
SetErrorCode(KO);
if( theFileName.IsEmpty() ) return NULL;
STEPPlugin_IImport aCI( aFunction );
aCI.SetFileName( theFileName );
aCI.SetIsIgnoreUnits( theIsIgnoreUnits );
+ aCI.SetIsCreateAssemblies( IsCreateAssemblies );
//Perform the Import
Handle(TColStd_HSequenceOfTransient) aSeq = new TColStd_HSequenceOfTransient;
//Make a Python command
GEOM::TPythonDump pd (aFunction);
- if( theIsIgnoreUnits )
- pd << aSeq << " = geompy.ImportSTEP(\"" << theFileName.ToCString() << "\", True)";
- else
- pd << aSeq << " = geompy.ImportSTEP(\"" << theFileName.ToCString() << "\")";
+ pd << aSeq << " = geompy.ImportSTEP(\"" << theFileName.ToCString() << "\", ";
+ pd << (theIsIgnoreUnits ? "True" : "False");
+ pd << ", " << (IsCreateAssemblies ? "True" : "False");
+ pd << ")";
SetErrorCode(OK);
return aSeq;
void ExportSTEP( const Handle(GEOM_Object),
const TCollection_AsciiString&, const LengthUnit );
- Handle(TColStd_HSequenceOfTransient) ImportSTEP( const TCollection_AsciiString&,
- const bool );
+ Handle(TColStd_HSequenceOfTransient) ImportSTEP(const TCollection_AsciiString&,
+ const bool,
+ const bool);
TCollection_AsciiString ReadValue( const TCollection_AsciiString&,
const TCollection_AsciiString& );
* \param theIsIgnoreUnits If True, file length units will be ignored (set to 'meter')
* and result model will be scaled, if its units are not meters.
* If False (default), file length units will be taken into account.
+ * \param IsCreateAssemblies If True, for each assembly compound is created
+ * in the result. If False Compounds that contain a
+ * single shape are eliminated from the result.
* \return List of GEOM_Objects, containing the created shape and propagation groups.
*/
//=============================================================================
-GEOM::ListOfGO* STEPPlugin_IOperations_i::ImportSTEP( const char* theFileName,
- const bool theIsIgnoreUnits = false )
+GEOM::ListOfGO* STEPPlugin_IOperations_i::ImportSTEP
+ (const char *theFileName,
+ const bool theIsIgnoreUnits,
+ const bool IsCreateAssemblies)
{
GEOM::ListOfGO_var aSeq = new GEOM::ListOfGO;
GetOperations()->SetNotDone();
//Import the shape from the file
- Handle(TColStd_HSequenceOfTransient) aHSeq = GetOperations()->ImportSTEP( theFileName, theIsIgnoreUnits );
+ Handle(TColStd_HSequenceOfTransient) aHSeq = GetOperations()->ImportSTEP
+ (theFileName, theIsIgnoreUnits, IsCreateAssemblies);
if( !GetOperations()->IsDone() || aHSeq.IsNull() )
return aSeq._retn();
void ExportSTEP( GEOM::GEOM_Object_ptr, const char*,
GEOM::length_unit );
- GEOM::ListOfGO* ImportSTEP( const char*, const bool );
+ GEOM::ListOfGO* ImportSTEP( const char*, const bool, const bool );
char* ReadValue( const char*, const char* );
STEPPlugin_IOperations* GetOperations();
--- /dev/null
+// Copyright (C) 2014-2015 CEA/DEN, EDF R&D, OPEN CASCADE
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#include "STEPPlugin_ImportDlg.h"
+
+#include <QApplication>
+#include <QLayout>
+#include <QCheckBox>
+
+//=============================================================================
+// Constructor
+//=============================================================================
+STEPPlugin_ImportDlg::STEPPlugin_ImportDlg(QWidget *parent)
+ : SUIT_FileDlg (parent, true, true, true),
+ myCheckBox (0)
+{
+ myCheckBox = new QCheckBox(tr("STEP_CREATE_ASSEMBLIES"), this);
+
+ myCheckBox->setChecked(true);
+
+ layout()->addWidget(myCheckBox);
+}
+
+//=============================================================================
+// Destructor
+//=============================================================================
+STEPPlugin_ImportDlg::~STEPPlugin_ImportDlg()
+{
+}
+
+//=============================================================================
+// IsCreateAssemblies
+//=============================================================================
+bool STEPPlugin_ImportDlg::IsCreateAssemblies() const
+{
+ return myCheckBox->isChecked();
+}
+
+//=============================================================================
+// getOpenFileNames
+//=============================================================================
+QStringList STEPPlugin_ImportDlg::getOpenFileNames
+ (const QString &theInitial,
+ const QString &theFilters,
+ const QString &theCaption,
+ QWidget *theParent,
+ bool &IsCreateAssemblies)
+{
+ STEPPlugin_ImportDlg anImpDlg(theParent);
+ QStringList aFilters = theFilters.split(";;", QString::SkipEmptyParts);
+
+ anImpDlg.setFileMode(ExistingFiles);
+
+ if (aFilters.isEmpty()) {
+ anImpDlg.setFilter(tr("ALL_FILES_FILTER")); // All files (*)
+ } else {
+ anImpDlg.setFilters(aFilters);
+ }
+
+ if (!theCaption.isEmpty()) {
+ anImpDlg.setWindowTitle(theCaption);
+ }
+
+ if (!theInitial.isEmpty()) {
+ anImpDlg.processPath(theInitial);
+ }
+
+ QStringList aFileNames;
+
+ if (anImpDlg.exec() == QDialog::Accepted) {
+ aFileNames = anImpDlg.selectedFiles();
+ IsCreateAssemblies = anImpDlg.IsCreateAssemblies();
+ }
+
+ QApplication::processEvents();
+
+ return aFileNames;
+}
--- /dev/null
+// Copyright (C) 2014-2015 CEA/DEN, EDF R&D, OPEN CASCADE
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#ifndef STEPPlugin_ImportDlg_H
+#define STEPPlugin_ImportDlg_H
+
+#include <SUIT_FileDlg.h>
+#include <SALOMEconfig.h>
+#include CORBA_CLIENT_HEADER(STEPPlugin)
+
+class QCheckBox;
+
+class STEPPlugin_ImportDlg: public SUIT_FileDlg
+{
+ Q_OBJECT
+
+public:
+
+ STEPPlugin_ImportDlg(QWidget *parent);
+ ~STEPPlugin_ImportDlg();
+
+ bool IsCreateAssemblies() const;
+
+ static QStringList getOpenFileNames (const QString &theInitial,
+ const QString &theFilters,
+ const QString &theCaption,
+ QWidget *theParent,
+ bool &IsCreateAssemblies);
+
+private:
+
+ QCheckBox *myCheckBox;
+
+};
+
+#endif // STEPPlugin_ImportDlg_H
#include <StepGeom_GeometricRepresentationItem.hxx>
#include <StepShape_TopologicalRepresentationItem.hxx>
#include <StepRepr_DescriptiveRepresentationItem.hxx>
+#include <StepRepr_NextAssemblyUsageOccurrence.hxx>
#include <StepRepr_ProductDefinitionShape.hxx>
#include <StepRepr_PropertyDefinitionRepresentation.hxx>
#include <StepRepr_Representation.hxx>
#include <BRep_Builder.hxx>
#include <TopExp.hxx>
#include <TopExp_Explorer.hxx>
+#include <TopTools_DataMapOfShapeShape.hxx>
#include <TopTools_IndexedMapOfShape.hxx>
+#include <TopTools_ListIteratorOfListOfShape.hxx>
+#include <TopTools_ListOfShape.hxx>
+#include <TopTools_MapOfShape.hxx>
#include <TopoDS_Compound.hxx>
#include <TopoDS_Iterator.hxx>
#include <TColStd_SequenceOfAsciiString.hxx>
return aResult;
}
+ //=============================================================================
+ /*!
+ * GetAllParents()
+ */
+ //=============================================================================
+
+ Standard_Boolean GetAllParents(const TopoDS_Shape &theShape,
+ const TopoDS_Shape &theSubShape,
+ TopTools_ListOfShape &theParents)
+ {
+ const TopAbs_ShapeEnum aSubShType = theSubShape.ShapeType();
+ Standard_Boolean aResult = Standard_False;
+
+ if (theShape.ShapeType() >= aSubShType) {
+ return aResult; // NULL shape
+ }
+
+ TopoDS_Iterator anIt(theShape);
+ TopTools_MapOfShape aMapFence;
+
+ for (; anIt.More(); anIt.Next()) {
+ const TopoDS_Shape &aSubShape = anIt.Value();
+
+ if (aMapFence.Add(aSubShape)) {
+ if (theSubShape.IsSame(aSubShape)) {
+ // The sub-shape is found. theShape is its parent.
+ theParents.Append(theShape);
+ aResult = Standard_True;
+ break;
+ }
+
+ if (aSubShape.ShapeType() < aSubShType) {
+ if (GetAllParents(aSubShape, theSubShape, theParents)) {
+ // The sub-shape is found.
+ theParents.Append(theShape);
+ aResult = Standard_True;
+ break;
+ }
+ }
+ }
+ }
+
+ return aResult;
+ }
+
+ //=============================================================================
+ /*!
+ * BuildModifiedShape()
+ */
+ //=============================================================================
+
+ TopoDS_Shape BuildModifiedShape
+ (const TopoDS_Shape &theShape,
+ TopTools_DataMapOfShapeShape &theMapModified)
+ {
+ // Check if the shape is modified.
+ TopoDS_Shape aFwdShape = theShape.Oriented(TopAbs_FORWARD);
+ TopoDS_Iterator anIt(aFwdShape);
+ Standard_Boolean isModified = Standard_False;
+
+ for (; anIt.More(); anIt.Next()) {
+ if (theMapModified.IsBound(anIt.Value())) {
+ isModified = Standard_True;
+ break;
+ }
+ }
+
+ TopoDS_Shape aResult;
+
+ if (isModified) {
+ BRep_Builder aBuilder;
+
+ aResult = aFwdShape.EmptyCopied();
+
+ for (anIt.Initialize(aFwdShape); anIt.More(); anIt.Next()) {
+ const TopoDS_Shape &aSubShape = anIt.Value();
+
+ if (theMapModified.IsBound(aSubShape)) {
+ TopoDS_Shape aModifSubShape = theMapModified.Find(aSubShape);
+
+ if (aModifSubShape.IsNull()) {
+ // Recursively compute the sub-shape.
+ aModifSubShape = BuildModifiedShape(aSubShape, theMapModified);
+ }
+
+ aBuilder.Add(aResult, aModifSubShape);
+ } else {
+ aBuilder.Add(aResult, aSubShape);
+ }
+ }
+
+ // Set the result shape orienation.
+ aResult.Orientation(theShape.Orientation());
+ theMapModified.Bind(theShape, aResult);
+ } else {
+ aResult = theShape;
+ }
+
+ return aResult;
+ }
+
+ //=============================================================================
+ /*!
+ * CreateAssemblies()
+ */
+ //=============================================================================
+
+ TopoDS_Shape CreateAssemblies
+ (const STEPControl_Reader &theReader,
+ const TopoDS_Shape &theShape,
+ TopTools_DataMapOfShapeShape &theMapShapeAssembly)
+ {
+ TopoDS_Shape aResult = theShape;
+ Handle(XSControl_TransferReader) aTR = theReader.WS()->TransferReader();
+ TopTools_ListOfShape aListAssemblies;
+
+ if (!aTR.IsNull()) {
+ Handle(Interface_InterfaceModel) aModel = theReader.WS()->Model();
+ Handle(Transfer_TransientProcess) aTP = aTR->TransientProcess();
+ Standard_Integer aNbEntities = aModel->NbEntities();
+ Standard_Integer i;
+ Handle(Standard_Type) aNAUOType =
+ STANDARD_TYPE(StepRepr_NextAssemblyUsageOccurrence);
+
+ for (i = 1; i <= aNbEntities; i++) {
+ Handle(Standard_Transient) anEnti = aModel->Value(i);
+
+ if (anEnti->IsKind(aNAUOType)) {
+ // This is an assembly. Find target shape
+ TopoDS_Shape aShape = GetShape(anEnti, aTP);
+
+ if (aShape.IsNull()) {
+ continue;
+ }
+
+ if (aShape.ShapeType() != TopAbs_COMPOUND) {
+ aListAssemblies.Append(aShape);
+ }
+ }
+ }
+ }
+
+ // Create assemblies.
+ if (!aListAssemblies.IsEmpty()) {
+ TopTools_ListIteratorOfListOfShape anIter(aListAssemblies);
+ BRep_Builder aBuilder;
+
+ for (; anIter.More(); anIter.Next()) {
+ const TopoDS_Shape &aShape = anIter.Value();
+ TopTools_ListOfShape aParents;
+
+ if (GetAllParents(theShape, aShape, aParents) &&
+ aParents.First().ShapeType() == TopAbs_COMPOUND) {
+ TopoDS_Compound aComp;
+ TopTools_ListIteratorOfListOfShape aParentIter(aParents);
+
+ // Fill theMapShapeAssembly.
+ for (; aParentIter.More(); aParentIter.Next()) {
+ theMapShapeAssembly.Bind(aParentIter.Value(), TopoDS_Shape());
+ }
+
+ aBuilder.MakeCompound(aComp);
+ aBuilder.Add(aComp, aShape);
+ theMapShapeAssembly.Bind(aShape, aComp);
+ }
+ }
+
+ // Build a new shape.
+ aResult = BuildModifiedShape(theShape, theMapShapeAssembly);
+ }
+
+ return aResult;
+ }
+
//=============================================================================
/*!
* StoreName()
*/
//=============================================================================
- void StoreName( const Handle(Standard_Transient) &theEnti,
- const TopTools_IndexedMapOfShape &theIndices,
- const Handle(Transfer_TransientProcess) &theTP,
- const TDF_Label &theShapeLabel)
+ void StoreName(const Handle(Standard_Transient) &theEnti,
+ const TopTools_IndexedMapOfShape &theIndices,
+ const Handle(XSControl_WorkSession) &theWS,
+ const Handle(Transfer_TransientProcess) &theTP,
+ const TDF_Label &theShapeLabel,
+ TopTools_DataMapOfShapeShape &theMapShapeAssembly)
{
Handle(TCollection_HAsciiString) aName;
if (theEnti->IsKind(STANDARD_TYPE(StepShape_TopologicalRepresentationItem)) ||
theEnti->IsKind(STANDARD_TYPE(StepGeom_GeometricRepresentationItem))) {
aName = Handle(StepRepr_RepresentationItem)::DownCast(theEnti)->Name();
+ } else if (theEnti->IsKind(STANDARD_TYPE(StepRepr_NextAssemblyUsageOccurrence))) {
+ Handle(StepRepr_NextAssemblyUsageOccurrence) aNAUO =
+ Handle(StepRepr_NextAssemblyUsageOccurrence)::DownCast(theEnti);
+
+ Interface_EntityIterator aSubs = theWS->Graph().Sharings(aNAUO);
+
+ for (aSubs.Start(); aSubs.More(); aSubs.Next()) {
+ Handle(StepRepr_ProductDefinitionShape) aPDS =
+ Handle(StepRepr_ProductDefinitionShape)::DownCast(aSubs.Value());
+
+ if(aPDS.IsNull()) {
+ continue;
+ }
+
+ Handle(StepBasic_ProductDefinitionRelationship) aPDR =
+ aPDS->Definition().ProductDefinitionRelationship();
+
+ if (aPDR.IsNull()) {
+ continue;
+ }
+
+ if (aPDR->HasDescription() && aPDR->Description()->Length() >0) {
+ aName = aPDR->Description();
+ } else if (!aPDR->Name().IsNull() && aPDR->Name()->Length() >0 ) {
+ aName = aPDR->Name();
+ } else if (!aPDR->Id().IsNull()) {
+ aName = aPDR->Id();
+ }
+ }
} else {
Handle(StepBasic_ProductDefinition) PD =
Handle(StepBasic_ProductDefinition)::DownCast(theEnti);
// find target shape
TopoDS_Shape S = GetShape(theEnti, theTP);
+ if (theMapShapeAssembly.IsBound(S)) {
+ S = theMapShapeAssembly.Find(S);
+ }
+
if (S.IsNull()) {
return;
}
TCollection_AsciiString aFileName = aData.GetFileName().ToCString();
bool anIsIgnoreUnits = aData.GetIsIgnoreUnits();
+ bool isCreateAssemblies = aData.GetIsCreateAssemblies();
TDF_Label aShapeLabel = aFunction->GetNamingEntry();
MESSAGE("Import STEP from file " << aFileName.ToCString() );
aReader.PrintCheckLoad(failsonly, IFSelect_ItemsByEntity);
// Root transfers
- Standard_Integer nbr = aReader.NbRootsForTransfer();
+ Standard_Integer aNbRoots = aReader.NbRootsForTransfer();
+ Standard_Integer i;
+
aReader.PrintCheckTransfer(failsonly, IFSelect_ItemsByEntity);
- for (Standard_Integer n = 1; n <= nbr; n++) {
- Standard_Boolean ok = aReader.TransferRoot(n);
- // Collecting resulting entities
- Standard_Integer nbs = aReader.NbShapes();
- if (!ok || nbs == 0)
- continue; // skip empty root
-
- // For a single entity
- else if (nbr == 1 && nbs == 1) {
- aResShape = aReader.Shape(1);
- if (aResShape.ShapeType() == TopAbs_COMPOUND) {
- int nbSub1 = 0;
- TopoDS_Shape currShape;
- TopoDS_Iterator It (aResShape, Standard_True, Standard_True);
- for (; It.More(); It.Next()) {
- nbSub1++;
- currShape = It.Value();
- }
- if (nbSub1 == 1)
- aResShape = currShape;
+ for (i = 1; i <= aNbRoots; i++) {
+ aReader.TransferRoot(i);
+ }
+
+ // Create result shape
+ const Standard_Integer aNbShapes = aReader.NbShapes();
+ TopTools_ListOfShape aListResShapes;
+
+ if (isCreateAssemblies) {
+ for (i = 1; i <= aNbShapes; i++) {
+ TopoDS_Shape aShape = aReader.Shape(i);
+
+ if (aShape.IsNull()) {
+ continue;
}
- break;
- }
- for (Standard_Integer i = 1; i <= nbs; i++) {
+ aListResShapes.Append(aShape);
+ }
+ } else {
+ for (i = 1; i <= aNbShapes; i++) {
TopoDS_Shape aShape = aReader.Shape(i);
- if (aShape.IsNull())
+
+ if (aShape.IsNull()) {
continue;
- else
- B.Add(compound, aShape);
+ }
+
+ if (aShape.ShapeType() == TopAbs_COMPOUND) {
+ int aNbSub = 0;
+ TopoDS_Shape aSubShape;
+ TopoDS_Iterator anIt (aShape, Standard_True, Standard_True);
+
+ for (; anIt.More(); anIt.Next()) {
+ aNbSub++;
+ aSubShape = anIt.Value();
+ }
+
+ if (aNbSub == 1) {
+ // Use the single sub-shape
+ aListResShapes.Append(aSubShape);
+ } else if (aNbSub > 1) {
+ // Use the shape
+ aListResShapes.Append(aShape);
+ }
+ }
+ }
+ }
+
+ // Construct result shape.
+ if (!aListResShapes.IsEmpty()) {
+ if (aListResShapes.Extent() == 1) {
+ // Use the single shape.
+ aResShape = aListResShapes.First();
+ } else {
+ // Make a compound of result shapes.
+ TopTools_ListIteratorOfListOfShape anIt(aListResShapes);
+
+ for (; anIt.More(); anIt.Next()) {
+ B.Add(compound, anIt.Value());
+ }
+
+ aResShape = compound;
}
}
- if( aResShape.IsNull() )
- aResShape = compound;
+
+ if( aResShape.IsNull() ) {
+ StdFail_NotDone::Raise("Null result shape");
+ return 0;
+ }
// Check if any BRep entity has been read, there must be at least a vertex
if ( !TopExp_Explorer( aResShape, TopAbs_VERTEX ).More() )
StdFail_NotDone::Raise( "No geometrical data in the imported file." );
+ // Create assemblies in the shape, if they are not created yet.
+ TopTools_DataMapOfShapeShape aMapShapeAssembly;
+
+ if (isCreateAssemblies) {
+ aResShape = CreateAssemblies(aReader, aResShape, aMapShapeAssembly);
+ }
+
// BEGIN: Store names and materials of sub-shapes from file
TopTools_IndexedMapOfShape anIndices;
TopExp::MapShapes(aResShape, anIndices);
Handle(Standard_Transient) enti = Model->Value(ie);
// Store names.
- StoreName(enti, anIndices, TP, aShapeLabel);
+ StoreName(enti, anIndices, aReader.WS(),
+ TP, aShapeLabel, aMapShapeAssembly);
// Store materials.
StoreMaterial(enti, anIndices, TP, aShapeLabel);
AddParam( theParams, "File name", aCI.GetFileName() );
if( aCI.GetIsIgnoreUnits() )
AddParam( theParams, "Format", "STEP_SCALE" );
+ AddParam( theParams, "Create Assemblies", aCI.GetIsCreateAssemblies() );
break;
default:
return false;
<translation>microinch</translation>
</message>
</context>
+<context>
+ <name>STEPPlugin_ImportDlg</name>
+ <message>
+ <source>STEP_CREATE_ASSEMBLIES</source>
+ <translation>Create assemblies</translation>
+ </message>
+</context>
</TS>