-// Copyright (C) 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE
//
// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
* that declare methods named GetObject - to apply the same rules of GetObject renaming
* and thus to avoid mess with GetObject symbol on Windows */
+#include <LDOMParser.hxx>
+
+#ifdef WNT
+#include <windows.h>
+#else
+#include <unistd.h>
+#endif
+
+
IMPLEMENT_STANDARD_HANDLE (_pyObject ,Standard_Transient);
IMPLEMENT_STANDARD_HANDLE (_pyCommand ,Standard_Transient);
+IMPLEMENT_STANDARD_HANDLE (_pyHypothesisReader,Standard_Transient);
IMPLEMENT_STANDARD_HANDLE (_pyGen ,_pyObject);
IMPLEMENT_STANDARD_HANDLE (_pyMesh ,_pyObject);
IMPLEMENT_STANDARD_HANDLE (_pySubMesh ,_pyObject);
IMPLEMENT_STANDARD_RTTIEXT(_pyObject ,Standard_Transient);
IMPLEMENT_STANDARD_RTTIEXT(_pyCommand ,Standard_Transient);
+IMPLEMENT_STANDARD_RTTIEXT(_pyHypothesisReader,Standard_Transient);
IMPLEMENT_STANDARD_RTTIEXT(_pyGen ,_pyObject);
IMPLEMENT_STANDARD_RTTIEXT(_pyMesh ,_pyObject);
IMPLEMENT_STANDARD_RTTIEXT(_pySubMesh ,_pyObject);
for ( ; id != idList.end(); ++id )
presentObjects.insert( *id );
}
+
+ //================================================================================
+ /*!
+ * \brief Fix SMESH::FunctorType arguments of SMESH::Filter::Criterion()
+ */
+ //================================================================================
+
+ void fixFunctorType( TCollection_AsciiString& Type,
+ TCollection_AsciiString& Compare,
+ TCollection_AsciiString& UnaryOp,
+ TCollection_AsciiString& BinaryOp )
+ {
+ // The problem is that dumps of old studies created using filters becomes invalid
+ // when new items are inserted in the enum SMESH::FunctorType since values
+ // of this enum are dumped as integer values.
+ // This function corrects enum values of old studies given as args (Type,Compare,...)
+ // We can find out how to correct them by value of BinaryOp which can have only two
+ // values: FT_Undefined or FT_LogicalNOT.
+ // Hereafter is the history of the enum SMESH::FunctorType since v3.0.0
+ // where PythonDump appeared
+ // v 3.0.0: FT_Undefined == 25
+ // v 3.1.0: FT_Undefined == 26, new items:
+ // - FT_Volume3D = 7
+ // v 4.1.2: FT_Undefined == 27, new items:
+ // - FT_BelongToGenSurface = 17
+ // v 5.1.1: FT_Undefined == 32, new items:
+ // - FT_FreeNodes = 10
+ // - FT_FreeFaces = 11
+ // - FT_LinearOrQuadratic = 23
+ // - FT_GroupColor = 24
+ // - FT_ElemGeomType = 25
+ // v 5.1.5: FT_Undefined == 33, new items:
+ // - FT_CoplanarFaces = 26
+ // v 6.2.0: FT_Undefined == 39, new items:
+ // - FT_MaxElementLength2D = 8
+ // - FT_MaxElementLength3D = 9
+ // - FT_BareBorderVolume = 25
+ // - FT_BareBorderFace = 26
+ // - FT_OverConstrainedVolume = 27
+ // - FT_OverConstrainedFace = 28
+ // v 6.5.0: FT_Undefined == 43, new items:
+ // - FT_EqualNodes = 14
+ // - FT_EqualEdges = 15
+ // - FT_EqualFaces = 16
+ // - FT_EqualVolumes = 17
+
+ typedef map< int, vector< int > > TUndef2newItems;
+ static TUndef2newItems undef2newItems;
+ if ( undef2newItems.empty() )
+ {
+ undef2newItems[ 26 ].push_back( 7 );
+ undef2newItems[ 27 ].push_back( 17 );
+ { int items[] = { 10, 11, 23, 24, 25 };
+ undef2newItems[ 32 ].assign( items, items+5 ); }
+ undef2newItems[ 33 ].push_back( 26 );
+ { int items[] = { 8, 9, 25, 26, 27, 28 };
+ undef2newItems[ 39 ].assign( items, items+6 ); }
+ { int items[] = { 14, 15, 16, 17 };
+ undef2newItems[ 43 ].assign( items, items+4 ); }
+ }
+
+ int iType = Type.IntegerValue();
+ int iCompare = Compare.IntegerValue();
+ int iUnaryOp = UnaryOp.IntegerValue();
+ int iBinaryOp = BinaryOp.IntegerValue();
+
+ // find out integer value of FT_Undefined at the moment of dump
+ int oldUndefined = iBinaryOp;
+ if ( iBinaryOp < iUnaryOp ) // BinaryOp was FT_LogicalNOT
+ oldUndefined += 3;
+
+ // apply history to args
+ TUndef2newItems::const_iterator undef_items =
+ undef2newItems.upper_bound( oldUndefined );
+ if ( undef_items != undef2newItems.end() )
+ {
+ int* pArg[4] = { &iType, &iCompare, &iUnaryOp, &iBinaryOp };
+ for ( ; undef_items != undef2newItems.end(); ++undef_items )
+ {
+ const vector< int > & addedItems = undef_items->second;
+ for ( size_t i = 0; i < addedItems.size(); ++i )
+ for ( int iArg = 0; iArg < 4; ++iArg )
+ {
+ int& arg = *pArg[iArg];
+ if ( arg >= addedItems[i] )
+ arg++;
+ }
+ }
+ Type = TCollection_AsciiString( iType );
+ Compare = TCollection_AsciiString( iCompare );
+ UnaryOp = TCollection_AsciiString( iUnaryOp );
+ BinaryOp = TCollection_AsciiString( iBinaryOp );
+ }
+ }
}
//================================================================================
method == "DoubleNodeGroupNew" ||
method == "DoubleNodeGroupsNew" ||
method == "DoubleNodeElemGroupNew" ||
- method == "DoubleNodeElemGroupsNew" )
+ method == "DoubleNodeElemGroupsNew"||
+ method == "DoubleNodeElemGroup2New"||
+ method == "DoubleNodeElemGroups2New"
+ )
groups = aCommand->GetResultValue();
else if ( method == "MakeBoundaryMesh" )
groups = aCommand->GetResultValue(2);
Tolerance = aCommand->GetArg(8), // double
TypeOfElement = aCommand->GetArg(9), // ElementType
Precision = aCommand->GetArg(10); // long
+ fixFunctorType( Type, Compare, UnaryOp, BinaryOp );
Type = SMESH + SMESH::FunctorTypeToString( SMESH::FunctorType( Type.IntegerValue() ));
Compare = SMESH + SMESH::FunctorTypeToString( SMESH::FunctorType( Compare.IntegerValue() ));
UnaryOp = SMESH + SMESH::FunctorTypeToString( SMESH::FunctorType( UnaryOp.IntegerValue() ));
{
for(int ind = 0;ind<theCommand->GetNbResultValues();ind++)
{
- const _pyID& meshID = theCommand->GetResultValue(ind+1);
+ _pyID meshID = theCommand->GetResultValue(ind+1);
if ( !theCommand->IsStudyEntry( meshID ) ) continue;
Handle(_pyMesh) mesh = new _pyMesh( theCommand, theCommand->GetResultValue(ind+1));
myMeshes.insert( make_pair( mesh->GetID(), mesh ));
for ( id_obj = myObjects.begin(); id_obj != myObjects.end(); ++id_obj )
id_obj->second->SetRemovedFromStudy( false );
}
+ else
+ {
+ // let hypotheses find referred objects in order to prevent clearing
+ // not published referred hyps (it's needed for hyps like "LayerDistribution")
+ list< Handle(_pyMesh) > fatherMeshes;
+ for ( hyp = myHypos.begin(); hyp != myHypos.end(); ++hyp )
+ if ( !hyp->IsNull() )
+ (*hyp)->GetReferredMeshesAndGeom( fatherMeshes );
+ }
// set myIsPublished = false to all objects depending on
// meshes built on a removed geometry
for ( id_mesh = myMeshes.begin(); id_mesh != myMeshes.end(); ++id_mesh )
myObjects.insert( make_pair( theObj->GetID(), theObj ));
}
+//================================================================================
+/*!
+ * \brief Re-register an object with other ID to make it Process() commands of
+ * other object having this ID
+ */
+//================================================================================
+
+void _pyGen::SetProxyObject( const _pyID& theID, Handle(_pyObject)& theObj )
+{
+ if ( theObj.IsNull() ) return;
+
+ if ( theObj->IsKind( STANDARD_TYPE( _pyMesh )))
+ myMeshes.insert( make_pair( theID, Handle(_pyMesh)::DownCast( theObj )));
+
+ else if ( theObj->IsKind( STANDARD_TYPE( _pyMeshEditor )))
+ myMeshEditors.insert( make_pair( theID, Handle(_pyMeshEditor)::DownCast( theObj )));
+
+ else
+ myObjects.insert( make_pair( theID, theObj ));
+}
+
//================================================================================
/*!
* \brief Finds a _pyObject by ID
if ( myGeomIDNb )
{
return ( myGeomIDIndex <= theObjID.Length() &&
- int( theObjID.Value( myGeomIDIndex )) == myGeomIDNb);
+ int( theObjID.Value( myGeomIDIndex )) == myGeomIDNb &&
+ _pyCommand::IsStudyEntry( theObjID ));
}
return false;
}
return true; // SMESH object not in study
}
+//================================================================================
+/*!
+ * \brief Return reader of hypotheses of plugins
+ */
+//================================================================================
+
+Handle( _pyHypothesisReader ) _pyGen::GetHypothesisReader() const
+{
+ if (myHypReader.IsNull() )
+ ((_pyGen*) this)->myHypReader = new _pyHypothesisReader;
+
+ return myHypReader;
+}
+
+
//================================================================================
/*!
* \brief Mesh created by SMESH_Gen
}
}
// ----------------------------------------------------------------------
- else if ( method == "CreateGroup" ) // CreateGroup() --> CreateEmptyGroup()
- {
- theCommand->SetMethod( "CreateEmptyGroup" );
- Handle(_pyGroup) group = new _pyGroup( theCommand );
- myGroups.push_back( group );
- theGen->AddObject( group );
- }
- // ----------------------------------------------------------------------
- else if ( method == "CreateGroupFromGEOM" ) {// (type, name, grp)
- _pyID grp = theCommand->GetArg( 3 );
- // VSR 24/12/2010. PAL21106: always use GroupOnGeom() function on dump
- // next if(){...} section is commented
- //if ( sameGroupType( grp, theCommand->GetArg( 1 )) ) { // --> Group(grp)
- // theCommand->SetMethod( "Group" );
- // theCommand->RemoveArgs();
- // theCommand->SetArg( 1, grp );
- //}
- //else {
- // ------------------------->>>>> GroupOnGeom( grp, name, typ )
- _pyID type = theCommand->GetArg( 1 );
- _pyID name = theCommand->GetArg( 2 );
- theCommand->SetMethod( "GroupOnGeom" );
- theCommand->RemoveArgs();
- theCommand->SetArg( 1, grp );
- theCommand->SetArg( 2, name );
- theCommand->SetArg( 3, type );
- //}
- Handle(_pyGroup) group = new _pyGroup( theCommand );
- myGroups.push_back( group );
- theGen->AddObject( group );
- }
- // ----------------------------------------------------------------------
- else if ( method == "CreateGroupFromFilter" ) // --> GroupOnFilter()
+ else if ( method == "CreateGroup" ||
+ method == "CreateGroupFromGEOM" ||
+ method == "CreateGroupFromFilter" )
{
- theCommand->SetMethod( "GroupOnFilter" );
Handle(_pyGroup) group = new _pyGroup( theCommand );
myGroups.push_back( group );
theGen->AddObject( group );
-
- // GroupOnFilter(typ, name, aFilter0x4743dc0 -> aFilter_1)
- _pyID filterID = theCommand->GetArg(3);
- Handle(_pyFilter) filter = Handle(_pyFilter)::DownCast( theGen->FindObject( filterID ));
- if ( !filter.IsNull())
- {
- filter->Process( theCommand );
- filter->AddUser( group );
- }
}
// ----------------------------------------------------------------------
else if ( theCommand->MethodStartsFrom( "Export" ))
isPyMeshMethod=true;
theCommand->SetMethod("FindCoincidentNodesOnPart");
}
- // DoubleNodeElemGroupNew() -> DoubleNodeElemGroup()
- // DoubleNodeGroupNew() -> DoubleNodeGroup()
- // DoubleNodeGroupsNew() -> DoubleNodeGroups()
- // DoubleNodeElemGroupsNew() -> DoubleNodeElemGroups()
+ // DoubleNode...New(...) -> DoubleNode...(...,True)
if ( !isPyMeshMethod && ( method == "DoubleNodeElemGroupNew" ||
method == "DoubleNodeElemGroupsNew" ||
method == "DoubleNodeGroupNew" ||
- method == "DoubleNodeGroupsNew"))
+ method == "DoubleNodeGroupsNew" ||
+ method == "DoubleNodeElemGroup2New" ||
+ method == "DoubleNodeElemGroups2New"))
{
isPyMeshMethod=true;
- theCommand->SetMethod( method.SubString( 1, method.Length()-3));
- theCommand->SetArg(theCommand->GetNbArgs()+1,"True");
+ const int excessLen = 3 + int( method.Value( method.Length()-3 ) == '2' );
+ theCommand->SetMethod( method.SubString( 1, method.Length()-excessLen));
+ if ( excessLen == 3 )
+ {
+ theCommand->SetArg(theCommand->GetNbArgs()+1,"True");
+ }
+ else if ( theCommand->GetArg(4) == "0" ||
+ theCommand->GetArg(5) == "0" )
+ {
+ // [ nothing, Group ] = DoubleNodeGroup2New(,,,False, True) ->
+ // Group = DoubleNodeGroup2New(,,,False, True)
+ _pyID groupID = theCommand->GetResultValue( 1 + int( theCommand->GetArg(4) == "0"));
+ theCommand->SetResultValue( groupID );
+ }
}
// ConvertToQuadraticObject(bool,obj) -> ConvertToQuadratic(bool,obj)
// ConvertFromQuadraticObject(obj) -> ConvertFromQuadratic(obj)
//================================================================================
_pyHypothesis::_pyHypothesis(const Handle(_pyCommand)& theCreationCmd):
- _pyObject( theCreationCmd )
+ _pyObject( theCreationCmd ), myCurCrMethod(0)
{
myIsAlgo = myIsWrapped = /*myIsConverted = myIsLocal = myDim = */false;
}
algo = new _pyAlgorithm( theCreationCmd );
hyp = new _pyHypothesis( theCreationCmd );
- // 1D Regular_1D ----------
- if ( hypType == "Regular_1D" ) {
- // set mesh's method creating algo,
- // i.e. convertion result will be "regular1d = Mesh.Segment()",
- // and set hypType by which algo creating a hypothesis is searched for
- algo->SetConvMethodAndType("Segment", hypType.ToCString());
- }
- else if ( hypType == "CompositeSegment_1D" ) {
- algo->SetConvMethodAndType("Segment", "Regular_1D");
- algo->myArgs.Append( "algo=smesh.COMPOSITE");
- }
- else if ( hypType == "LocalLength" ) {
- // set algo's method creating hyp, and algo type
- hyp->SetConvMethodAndType( "LocalLength", "Regular_1D");
- // set method whose 1 arg will become the 1-st arg of hyp creation command
- // i.e. convertion result will be "locallength = regular1d.LocalLength(<arg of SetLength()>)"
- hyp->AddArgMethod( "SetLength" );
- }
- else if ( hypType == "MaxLength" ) {
- // set algo's method creating hyp, and algo type
- hyp->SetConvMethodAndType( "MaxSize", "Regular_1D");
- // set method whose 1 arg will become the 1-st arg of hyp creation command
- // i.e. convertion result will be "maxsize = regular1d.MaxSize(<arg of SetLength()>)"
- hyp->AddArgMethod( "SetLength" );
- }
- else if ( hypType == "NumberOfSegments" ) {
+ if ( hypType == "NumberOfSegments" ) {
hyp = new _pyNumberOfSegmentsHyp( theCreationCmd );
hyp->SetConvMethodAndType( "NumberOfSegments", "Regular_1D");
// arg of SetNumberOfSegments() will become the 1-st arg of hyp creation command
// arg of SetScaleFactor() will become the 2-nd arg of hyp creation command
hyp->AddArgMethod( "SetScaleFactor" );
hyp->AddArgMethod( "SetReversedEdges" );
- }
- else if ( hypType == "Arithmetic1D" ) {
- hyp = new _pyComplexParamHypo( theCreationCmd );
- hyp->SetConvMethodAndType( "Arithmetic1D", "Regular_1D");
- hyp->AddArgMethod( "SetStartLength" );
- hyp->AddArgMethod( "SetEndLength" );
- hyp->AddArgMethod( "SetReversedEdges" );
- }
- else if ( hypType == "StartEndLength" ) {
- hyp = new _pyComplexParamHypo( theCreationCmd );
- hyp->SetConvMethodAndType( "StartEndLength", "Regular_1D");
- hyp->AddArgMethod( "SetStartLength" );
- hyp->AddArgMethod( "SetEndLength" );
+ // same for ""CompositeSegment_1D:
+ hyp->SetConvMethodAndType( "NumberOfSegments", "CompositeSegment_1D");
+ hyp->AddArgMethod( "SetNumberOfSegments" );
+ hyp->AddArgMethod( "SetScaleFactor" );
hyp->AddArgMethod( "SetReversedEdges" );
}
- else if ( hypType == "Deflection1D" ) {
- hyp->SetConvMethodAndType( "Deflection1D", "Regular_1D");
- hyp->AddArgMethod( "SetDeflection" );
- }
- else if ( hypType == "Propagation" ) {
- hyp->SetConvMethodAndType( "Propagation", "Regular_1D");
- }
- else if ( hypType == "QuadraticMesh" ) {
- hyp->SetConvMethodAndType( "QuadraticMesh", "Regular_1D");
- }
- else if ( hypType == "AutomaticLength" ) {
- hyp->SetConvMethodAndType( "AutomaticLength", "Regular_1D");
- hyp->AddArgMethod( "SetFineness");
- }
else if ( hypType == "SegmentLengthAroundVertex" ) {
hyp = new _pySegmentLengthAroundVertexHyp( theCreationCmd );
hyp->SetConvMethodAndType( "LengthNearVertex", "Regular_1D" );
hyp->AddArgMethod( "SetLength" );
- }
- // 1D Python_1D ----------
- else if ( hypType == "Python_1D" ) {
- algo->SetConvMethodAndType( "Segment", hypType.ToCString());
- algo->myArgs.Append( "algo=smesh.PYTHON");
- }
- else if ( hypType == "PythonSplit1D" ) {
- hyp->SetConvMethodAndType( "PythonSplit1D", "Python_1D");
- hyp->AddArgMethod( "SetNumberOfSegments");
- hyp->AddArgMethod( "SetPythonLog10RatioFunction");
- }
- // MEFISTO_2D ----------
- else if ( hypType == "MEFISTO_2D" ) { // MEFISTO_2D
- algo->SetConvMethodAndType( "Triangle", hypType.ToCString());
- }
- else if ( hypType == "MaxElementArea" ) {
- hyp->SetConvMethodAndType( "MaxElementArea", "MEFISTO_2D");
- hyp->SetConvMethodAndType( "MaxElementArea", "NETGEN_2D_ONLY");
- hyp->AddArgMethod( "SetMaxElementArea");
- }
- else if ( hypType == "LengthFromEdges" ) {
- hyp->SetConvMethodAndType( "LengthFromEdges", "MEFISTO_2D");
- hyp->SetConvMethodAndType( "LengthFromEdges", "NETGEN_2D_ONLY");
- }
- // Quadrangle_2D ----------
- else if ( hypType == "Quadrangle_2D" ) {
- algo->SetConvMethodAndType( "Quadrangle" , hypType.ToCString());
- }
- else if ( hypType == "QuadranglePreference" ) {
- hyp->SetConvMethodAndType( "QuadranglePreference", "Quadrangle_2D");
- hyp->SetConvMethodAndType( "SetQuadAllowed", "NETGEN_2D_ONLY");
- }
- else if ( hypType == "TrianglePreference" ) {
- hyp->SetConvMethodAndType( "TrianglePreference", "Quadrangle_2D");
- }
- // RadialQuadrangle_1D2D ----------
- else if ( hypType == "RadialQuadrangle_1D2D" ) {
- algo->SetConvMethodAndType( "Quadrangle" , hypType.ToCString());
- algo->myArgs.Append( "algo=smesh.RADIAL_QUAD" );
- }
- else if ( hypType == "NumberOfLayers2D" ) {
- hyp->SetConvMethodAndType( "NumberOfLayers", "RadialQuadrangle_1D2D");
- hyp->AddArgMethod( "SetNumberOfLayers" );
+ // same for ""CompositeSegment_1D:
+ hyp->SetConvMethodAndType( "LengthNearVertex", "CompositeSegment_1D");
+ hyp->AddArgMethod( "SetLength" );
}
else if ( hypType == "LayerDistribution2D" ) {
hyp = new _pyLayerDistributionHypo( theCreationCmd, "Get2DHypothesis" );
hyp->SetConvMethodAndType( "LayerDistribution", "RadialQuadrangle_1D2D");
}
- // BLSURF ----------
- else if ( hypType == "BLSURF" ) {
- algo->SetConvMethodAndType( "Triangle", hypType.ToCString());
- algo->myArgs.Append( "algo=smesh.BLSURF" );
- }
- else if ( hypType == "BLSURF_Parameters") {
- hyp->SetConvMethodAndType( "Parameters", "BLSURF");
- }
- // NETGEN ----------
- else if ( hypType == "NETGEN_2D") { // 1D-2D
- algo->SetConvMethodAndType( "Triangle" , hypType.ToCString());
- algo->myArgs.Append( "algo=smesh.NETGEN" );
- }
- else if ( hypType == "NETGEN_Parameters_2D") {
- hyp->SetConvMethodAndType( "Parameters", "NETGEN_2D");
- }
- else if ( hypType == "NETGEN_SimpleParameters_2D") {
- hyp->SetConvMethodAndType( "Parameters", "NETGEN_2D");
- hyp->myArgs.Append( "which=smesh.SIMPLE" );
- }
- else if ( hypType == "NETGEN_2D3D") { // 1D-2D-3D
- algo->SetConvMethodAndType( "Tetrahedron" , hypType.ToCString());
- algo->myArgs.Append( "algo=smesh.FULL_NETGEN" );
- }
- else if ( hypType == "NETGEN_Parameters") {
- hyp->SetConvMethodAndType( "Parameters", "NETGEN_2D3D");
- }
- else if ( hypType == "NETGEN_SimpleParameters_3D") {
- hyp->SetConvMethodAndType( "Parameters", "NETGEN_2D3D");
- hyp->myArgs.Append( "which=smesh.SIMPLE" );
- }
- else if ( hypType == "NETGEN_2D_ONLY") { // 2D
- algo->SetConvMethodAndType( "Triangle" , hypType.ToCString());
- algo->myArgs.Append( "algo=smesh.NETGEN_2D" );
- }
- else if ( hypType == "NETGEN_3D") { // 3D
- algo->SetConvMethodAndType( "Tetrahedron" , hypType.ToCString());
- algo->myArgs.Append( "algo=smesh.NETGEN" );
- }
- else if ( hypType == "MaxElementVolume") {
- hyp->SetConvMethodAndType( "MaxElementVolume", "NETGEN_3D");
- hyp->AddArgMethod( "SetMaxElementVolume" );
- }
- // GHS3D_3D ----------
- else if ( hypType == "GHS3D_3D" ) {
- algo->SetConvMethodAndType( "Tetrahedron", hypType.ToCString());
- algo->myArgs.Append( "algo=smesh.GHS3D" );
- }
- else if ( hypType == "GHS3D_Parameters") {
- hyp->SetConvMethodAndType( "Parameters", "GHS3D_3D");
- }
- // Hexa_3D ---------
- else if ( hypType == "Hexa_3D" ) {
- algo->SetConvMethodAndType( "Hexahedron", hypType.ToCString());
- }
- // Repetitive Projection_1D ---------
- else if ( hypType == "Projection_1D" ) {
- algo->SetConvMethodAndType( "Projection1D", hypType.ToCString());
- }
- else if ( hypType == "ProjectionSource1D" ) {
- hyp->SetConvMethodAndType( "SourceEdge", "Projection_1D");
- hyp->AddArgMethod( "SetSourceEdge");
- hyp->AddArgMethod( "SetSourceMesh");
- // 2 args of SetVertexAssociation() will become the 3-th and 4-th args of hyp creation command
- hyp->AddArgMethod( "SetVertexAssociation", 2 );
- }
- // Projection_2D ---------
- else if ( hypType == "Projection_2D" ) {
- algo->SetConvMethodAndType( "Projection2D", hypType.ToCString());
- }
- else if ( hypType == "Projection_1D2D" ) {
- algo->SetConvMethodAndType( "Projection1D2D", hypType.ToCString());
- }
- else if ( hypType == "ProjectionSource2D" ) {
- hyp->SetConvMethodAndType( "SourceFace", "Projection_2D");
- hyp->SetConvMethodAndType( "SourceFace", "Projection_1D2D");
- hyp->AddArgMethod( "SetSourceFace");
- hyp->AddArgMethod( "SetSourceMesh");
- hyp->AddArgMethod( "SetVertexAssociation", 4 );
- }
- // Projection_3D ---------
- else if ( hypType == "Projection_3D" ) {
- algo->SetConvMethodAndType( "Projection3D", hypType.ToCString());
- }
- else if ( hypType == "ProjectionSource3D" ) {
- hyp->SetConvMethodAndType( "SourceShape3D", "Projection_3D");
- hyp->AddArgMethod( "SetSource3DShape");
- hyp->AddArgMethod( "SetSourceMesh");
- hyp->AddArgMethod( "SetVertexAssociation", 4 );
- }
- // Prism_3D ---------
- else if ( hypType == "Prism_3D" ) {
- algo->SetConvMethodAndType( "Prism", hypType.ToCString());
- }
- // RadialPrism_3D ---------
- else if ( hypType == "RadialPrism_3D" ) {
- algo->SetConvMethodAndType( "Prism", hypType.ToCString());
- }
- else if ( hypType == "NumberOfLayers" ) {
- hyp->SetConvMethodAndType( "NumberOfLayers", "RadialPrism_3D");
- hyp->AddArgMethod( "SetNumberOfLayers" );
- }
else if ( hypType == "LayerDistribution" ) {
hyp = new _pyLayerDistributionHypo( theCreationCmd, "Get3DHypothesis" );
hyp->SetConvMethodAndType( "LayerDistribution", "RadialPrism_3D");
}
- // Cartesian 3D ---------
- else if ( hypType == "Cartesian_3D" ) {
- algo->SetConvMethodAndType( "BodyFitted", hypType.ToCString());
- }
else if ( hypType == "CartesianParameters3D" ) {
hyp = new _pyComplexParamHypo( theCreationCmd );
hyp->SetConvMethodAndType( "SetGrid", "Cartesian_3D");
for ( int iArg = 0; iArg < 4; ++iArg )
- hyp->myArgs.Append("[]");
+ hyp->setCreationArg( iArg+1, "[]");
+ }
+ else
+ {
+ hyp = theGen->GetHypothesisReader()->GetHypothesis( hypType, theCreationCmd );
}
return algo->IsValid() ? algo : hyp;
theCmd->SetResultValue( GetID() );
theCmd->SetObject( IsAlgo() ? theMesh : algo->GetID());
theCmd->SetMethod( IsAlgo() ? GetAlgoCreationMethod() : GetCreationMethod( algo->GetAlgoType() ));
- // set args
+ // set args (geom will be set by _pyMesh calling this method)
theCmd->RemoveArgs();
- for ( int i = 1; i <= myArgs.Length(); ++i ) {
- if ( !myArgs( i ).IsEmpty() )
- theCmd->SetArg( i, myArgs( i ));
+ for ( size_t i = 0; i < myCurCrMethod->myArgs.size(); ++i ) {
+ if ( !myCurCrMethod->myArgs[ i ].IsEmpty() )
+ theCmd->SetArg( i+1, myCurCrMethod->myArgs[ i ]);
else
- theCmd->SetArg( i, "[]");
+ theCmd->SetArg( i+1, "[]");
}
// set a new creation command
GetCreationCmd()->Clear();
// set unknown arg commands after hypo creation
Handle(_pyCommand) afterCmd = myIsWrapped ? theCmd : GetCreationCmd();
- list<Handle(_pyCommand)>::iterator cmd = myUnknownCommands.begin();
- for ( ; cmd != myUnknownCommands.end(); ++cmd ) {
+ list<Handle(_pyCommand)>::iterator cmd = myUnusedCommands.begin();
+ for ( ; cmd != myUnusedCommands.end(); ++cmd ) {
afterCmd->AddDependantCmd( *cmd );
}
if ( !theGen->IsToKeepAllCommands() )
rememberCmdOfParameter( theCommand );
// set args
- int nbArgs = 0;
- for ( int i = 1; i <= myArgMethods.Length(); ++i ) {
- if ( myArgMethods( i ) == theCommand->GetMethod() ) {
- while ( myArgs.Length() < nbArgs + myNbArgsByMethod( i ))
- myArgs.Append( "[]" );
- for ( int iArg = 1; iArg <= myNbArgsByMethod( i ); ++iArg )
- myArgs( nbArgs + iArg ) = theCommand->GetArg( iArg ); // arg value
- myArgCommands.push_back( theCommand );
- return;
+ bool usedCommand = false;
+ TType2CrMethod::iterator type2meth = myAlgoType2CreationMethod.begin();
+ for ( ; type2meth != myAlgoType2CreationMethod.end(); ++type2meth )
+ {
+ CreationMethod& crMethod = type2meth->second;
+ for ( size_t i = 0; i < crMethod.myArgMethods.size(); ++i ) {
+ if ( crMethod.myArgMethods[ i ] == theCommand->GetMethod() ) {
+ if ( !usedCommand )
+ myArgCommands.push_back( theCommand );
+ usedCommand = true;
+ while ( crMethod.myArgs.size() < i+1 )
+ crMethod.myArgs.push_back( "[]" );
+ crMethod.myArgs[ i ] = theCommand->GetArg( crMethod.myArgNb[i] );
+ }
}
- nbArgs += myNbArgsByMethod( i );
}
- myUnknownCommands.push_back( theCommand );
+ if ( !usedCommand )
+ myUnusedCommands.push_back( theCommand );
}
//================================================================================
// Add access to a wrapped algorithm
theGen->AddAlgoAccessorMethod( *cmd );
}
- cmd = myUnknownCommands.begin();
- for ( ; cmd != myUnknownCommands.end(); ++cmd ) {
+ cmd = myUnusedCommands.begin();
+ for ( ; cmd != myUnusedCommands.end(); ++cmd ) {
// Add access to a wrapped mesh
theGen->AddMeshAccessorMethod( *cmd );
// Add access to a wrapped algorithm
}
// forget previous hypothesis modifications
myArgCommands.clear();
- myUnknownCommands.clear();
+ myUnusedCommands.clear();
}
//================================================================================
list<Handle(_pyCommand)>::iterator cmd = myArgCommands.begin();
for ( ; cmd != myArgCommands.end(); ++cmd )
( *cmd )->Clear();
- cmd = myUnknownCommands.begin();
- for ( ; cmd != myUnknownCommands.end(); ++cmd )
+ cmd = myUnusedCommands.begin();
+ for ( ; cmd != myUnusedCommands.end(); ++cmd )
( *cmd )->Clear();
}
void _pyHypothesis::Assign( const Handle(_pyHypothesis)& theOther,
const _pyID& theMesh )
{
- myIsWrapped = false;
- myMesh = theMesh;
-
// myCreationCmd = theOther->myCreationCmd;
- myIsAlgo = theOther->myIsAlgo;
- myGeom = theOther->myGeom;
- myType2CreationMethod = theOther->myType2CreationMethod;
- myArgs = theOther->myArgs;
- myArgMethods = theOther->myArgMethods;
- myNbArgsByMethod = theOther->myNbArgsByMethod;
- myArgCommands = theOther->myArgCommands;
- myUnknownCommands = theOther->myUnknownCommands;
+ myIsAlgo = theOther->myIsAlgo;
+ myIsWrapped = false;
+ myGeom = theOther->myGeom;
+ myMesh = theMesh;
+ myAlgoType2CreationMethod = theOther->myAlgoType2CreationMethod;
+ //myArgCommands = theOther->myArgCommands;
+ //myUnusedCommands = theOther->myUnusedCommands;
+ // init myCurCrMethod
+ GetCreationMethod( theOther->GetAlgoType() );
}
//================================================================================
void _pyHypothesis::ClearCommands()
{
- if ( !theGen->IsToKeepAllCommands() )
- {
- bool isUsed = false;
- int lastComputeOrder = 0;
- list<Handle(_pyCommand) >::iterator cmd = myComputeCmds.begin();
- for ( ; cmd != myComputeCmds.end(); ++cmd )
- if ( ! (*cmd)->IsEmpty() )
- {
- isUsed = true;
- if ( (*cmd)->GetOrderNb() > lastComputeOrder )
- lastComputeOrder = (*cmd)->GetOrderNb();
- }
- if ( !isUsed )
- {
- SetRemovedFromStudy( true );
- }
- else
- {
- // clear my commands invoked after lastComputeOrder
- map<TCollection_AsciiString, list< Handle(_pyCommand) > >::iterator m2c;
- for ( m2c = myMeth2Commands.begin(); m2c != myMeth2Commands.end(); ++m2c )
- {
- list< Handle(_pyCommand)> & cmds = m2c->second;
- if ( !cmds.empty() && cmds.back()->GetOrderNb() > lastComputeOrder )
- cmds.back()->Clear();
- }
- }
- }
+ // if ( !theGen->IsToKeepAllCommands() )
+ // {
+ // bool isUsed = false;
+ // int lastComputeOrder = 0;
+ // list<Handle(_pyCommand) >::iterator cmd = myComputeCmds.begin();
+ // for ( ; cmd != myComputeCmds.end(); ++cmd )
+ // if ( ! (*cmd)->IsEmpty() )
+ // {
+ // isUsed = true;
+ // if ( (*cmd)->GetOrderNb() > lastComputeOrder )
+ // lastComputeOrder = (*cmd)->GetOrderNb();
+ // }
+ // if ( !isUsed )
+ // {
+ // SetRemovedFromStudy( true );
+ // }
+ // else
+ // {
+ // // clear my commands invoked after lastComputeOrder
+ // // map<TCollection_AsciiString, list< Handle(_pyCommand) > >::iterator m2c;
+ // // for ( m2c = myMeth2Commands.begin(); m2c != myMeth2Commands.end(); ++m2c )
+ // // {
+ // // list< Handle(_pyCommand)> & cmds = m2c->second;
+ // // if ( !cmds.empty() && cmds.back()->GetOrderNb() > lastComputeOrder )
+ // // cmds.back()->Clear();
+ // // }
+ // }
+ // }
_pyObject::ClearCommands();
}
if ( IsAlgo() ) return true;
bool geomPublished = true;
- TColStd_SequenceOfAsciiString args; args = myArgs;
-
- list<Handle(_pyCommand)>::iterator cmd = myUnknownCommands.begin();
- for ( ; cmd != myUnknownCommands.end(); ++cmd ) {
+ vector< _AString > args;
+ TType2CrMethod::iterator type2meth = myAlgoType2CreationMethod.begin();
+ for ( ; type2meth != myAlgoType2CreationMethod.end(); ++type2meth )
+ {
+ CreationMethod& crMethod = type2meth->second;
+ args.insert( args.end(), crMethod.myArgs.begin(), crMethod.myArgs.end());
+ }
+ list<Handle(_pyCommand)>::iterator cmd = myUnusedCommands.begin();
+ for ( ; cmd != myUnusedCommands.end(); ++cmd ) {
for ( int nb = (*cmd)->GetNbArgs(); nb; --nb )
- args.Append( (*cmd)->GetArg( nb ));
+ args.push_back( (*cmd)->GetArg( nb ));
}
- for ( int i = 1; i <= args.Length(); ++i )
+ for ( size_t i = 0; i < args.size(); ++i )
{
- list< _pyID > idList = _pyCommand::GetStudyEntries( args( i ));
+ list< _pyID > idList = _pyCommand::GetStudyEntries( args[ i ]);
+ if ( idList.empty() && !args[ i ].IsEmpty() )
+ idList.push_back( args[ i ]);
list< _pyID >::iterator id = idList.begin();
for ( ; id != idList.end(); ++id )
{
- Handle(_pyObject) obj = theGen->FindObject( *id );
+ Handle(_pyObject) obj = theGen->FindObject( *id );
+ if ( obj.IsNull() ) obj = theGen->FindHyp( *id );
if ( obj.IsNull() )
{
if ( theGen->IsGeomObject( *id ) && theGen->IsNotPublished( *id ))
Handle(_pyMesh) mesh = ObjectToMesh( obj );
if ( !mesh.IsNull() )
meshes.push_back( mesh );
+ // prevent clearing not published hyps referred e.g. by "LayerDistribution"
+ else if ( obj->IsKind( STANDARD_TYPE( _pyHypothesis )) && this->IsInStudy() )
+ obj->SetRemovedFromStudy( false );
}
}
}
if ( theCommand->GetString().FirstLocationInSet( "'\"", 1, theCommand->Length() ) &&
theCommand->GetNbArgs() > 1 )
{
- // mangle method by appending a 1st textual arg (what if it's a variable name?!!!)
+ // mangle method by appending a 1st textual arg
for ( int iArg = 1; iArg <= theCommand->GetNbArgs(); ++iArg )
{
const TCollection_AsciiString& arg = theCommand->GetArg( iArg );
}
myComputeAddr2Cmds.erase( theComputeCmd->GetAddress() );
}
-// void _pyHypothesis::ComputeSaved( const Handle(_pyCommand)& theComputeCommand )
-// {
-// }
+
+//================================================================================
+/*!
+ * \brief Sets an argNb-th argument of current creation command
+ * \param argNb - argument index countered from 1
+ */
+//================================================================================
+
+void _pyHypothesis::setCreationArg( const int argNb, const _AString& arg )
+{
+ if ( myCurCrMethod )
+ {
+ while ( myCurCrMethod->myArgs.size() < argNb )
+ myCurCrMethod->myArgs.push_back( "None" );
+ if ( arg.IsEmpty() )
+ myCurCrMethod->myArgs[ argNb-1 ] = "None";
+ else
+ myCurCrMethod->myArgs[ argNb-1 ] = arg;
+ }
+}
//================================================================================
if ( theCommand->GetMethod() == "SetSizeThreshold" )
{
- myArgs( 4 ) = theCommand->GetArg( 1 );
+ setCreationArg( 4, theCommand->GetArg( 1 ));
myArgCommands.push_back( theCommand );
return;
}
theCommand->GetMethod() == "SetGridSpacing" )
{
TCollection_AsciiString axis = theCommand->GetArg( theCommand->GetNbArgs() );
- int iArg = 1 + ( axis.Value(1) - '0' );
+ int iArg = axis.Value(1) - '0';
if ( theCommand->GetMethod() == "SetGrid" )
{
- myArgs( iArg ) = theCommand->GetArg( 1 );
+ setCreationArg( 1+iArg, theCommand->GetArg( 1 ));
}
else
{
- myArgs( iArg ) = "[ ";
- myArgs( iArg ) += theCommand->GetArg( 1 );
- myArgs( iArg ) += ", ";
- myArgs( iArg ) += theCommand->GetArg( 2 );
- myArgs( iArg ) += "]";
+ myCurCrMethod->myArgs[ iArg ] = "[ ";
+ myCurCrMethod->myArgs[ iArg ] += theCommand->GetArg( 1 );
+ myCurCrMethod->myArgs[ iArg ] += ", ";
+ myCurCrMethod->myArgs[ iArg ] += theCommand->GetArg( 2 );
+ myCurCrMethod->myArgs[ iArg ] += "]";
}
myArgCommands.push_back( theCommand );
rememberCmdOfParameter( theCommand );
// ex: hyp.SetLength(start, 1)
// hyp.SetLength(end, 0)
ASSERT(( theCommand->GetArg( 2 ).IsIntegerValue() ));
- int i = 2 - theCommand->GetArg( 2 ).IntegerValue();
- while ( myArgs.Length() < i )
- myArgs.Append( "[]" );
- myArgs( i ) = theCommand->GetArg( 1 ); // arg value
+ int i = 1 - theCommand->GetArg( 2 ).IntegerValue();
+ TType2CrMethod::iterator type2meth = myAlgoType2CreationMethod.begin();
+ for ( ; type2meth != myAlgoType2CreationMethod.end(); ++type2meth )
+ {
+ CreationMethod& crMethod = type2meth->second;
+ while ( crMethod.myArgs.size() < i+1 )
+ crMethod.myArgs.push_back( "[]" );
+ crMethod.myArgs[ i ] = theCommand->GetArg( 1 ); // arg value
+ }
myArgCommands.push_back( theCommand );
}
else
{
if ( IsWrapped() )
{
- list < Handle(_pyCommand) >::iterator cmd = myUnknownCommands.begin();
- for ( ; cmd != myUnknownCommands.end(); ++cmd )
+ list < Handle(_pyCommand) >::iterator cmd = myUnusedCommands.begin();
+ for ( ; cmd != myUnusedCommands.end(); ++cmd )
if ((*cmd)->GetMethod() == "SetObjectEntry" )
(*cmd)->Clear();
}
if ( theCommand->GetMethod() != "SetLayerDistribution" )
return;
- _pyID newName; // name for 1D hyp = "HypType" + "_Distribution"
-
const _pyID& hyp1dID = theCommand->GetArg( 1 );
- Handle(_pyHypothesis) hyp1d = theGen->FindHyp( hyp1dID );
- if ( hyp1d.IsNull() ) // apparently hypId changed at study restoration
- hyp1d = my1dHyp;
- else if ( !my1dHyp.IsNull() && hyp1dID != my1dHyp->GetID() ) {
- // 1D hypo is already set, so distribution changes and the old
- // 1D hypo is thrown away
- my1dHyp->ClearAllCommands();
- }
- my1dHyp = hyp1d;
-
- if ( !myArgCommands.empty() )
- myArgCommands.front()->Clear();
+ // Handle(_pyHypothesis) hyp1d = theGen->FindHyp( hyp1dID );
+ // if ( hyp1d.IsNull() && ! my1dHyp.IsNull()) // apparently hypId changed at study restoration
+ // {
+ // TCollection_AsciiString cmd =
+ // my1dHyp->GetCreationCmd()->GetIndentation() + hyp1dID + " = " + my1dHyp->GetID();
+ // Handle(_pyCommand) newCmd = theGen->AddCommand( cmd );
+ // theGen->SetCommandAfter( newCmd, my1dHyp->GetCreationCmd() );
+ // hyp1d = my1dHyp;
+ // }
+ // else if ( !my1dHyp.IsNull() && hyp1dID != my1dHyp->GetID() )
+ // {
+ // // 1D hypo is already set, so distribution changes and the old
+ // // 1D hypo is thrown away
+ // my1dHyp->ClearAllCommands();
+ // }
+ // my1dHyp = hyp1d;
+ // //my1dHyp->SetRemovedFromStudy( false );
+
+ // if ( !myArgCommands.empty() )
+ // myArgCommands.back()->Clear();
+ myCurCrMethod->myArgs.push_back( hyp1dID );
myArgCommands.push_back( theCommand );
}
{
// as creation of 1D hyp was written later then it's edition,
// we need to find all it's edition calls and process them
- if ( !my1dHyp.IsNull() )
- {
- _pyID hyp1dID = my1dHyp->GetCreationCmd()->GetResultValue();
+ list< Handle(_pyCommand) >::iterator cmd = myArgCommands.begin();
+ _pyID prevNewName;
+ for ( cmd = myArgCommands.begin(); cmd != myArgCommands.end(); ++cmd )
+ {
+ const _pyID& hyp1dID = (*cmd)->GetArg( 1 );
+ if ( hyp1dID.IsEmpty() ) continue;
+
+ Handle(_pyHypothesis) hyp1d = theGen->FindHyp( hyp1dID );
// make a new name for 1D hyp = "HypType" + "_Distribution"
_pyID newName;
- if ( my1dHyp->IsWrapped() ) {
- newName = my1dHyp->GetCreationCmd()->GetMethod();
+ if ( hyp1d.IsNull() ) // apparently hypId changed at study restoration
+ {
+ if ( prevNewName.IsEmpty() ) continue;
+ newName = prevNewName;
}
- else {
- TCollection_AsciiString hypTypeQuoted = my1dHyp->GetCreationCmd()->GetArg(1);
- newName = hypTypeQuoted.SubString( 2, hypTypeQuoted.Length() - 1 );
+ else
+ {
+ if ( hyp1d->IsWrapped() ) {
+ newName = hyp1d->GetCreationCmd()->GetMethod();
+ }
+ else {
+ TCollection_AsciiString hypTypeQuoted = hyp1d->GetCreationCmd()->GetArg(1);
+ newName = hypTypeQuoted.SubString( 2, hypTypeQuoted.Length() - 1 );
+ }
+ newName += "_Distribution";
+ prevNewName = newName;
+
+ hyp1d->GetCreationCmd()->SetResultValue( newName );
}
- newName += "_Distribution";
- my1dHyp->GetCreationCmd()->SetResultValue( newName );
-
list< Handle(_pyCommand) >& cmds = theGen->GetCommands();
list< Handle(_pyCommand) >::iterator cmdIt = cmds.begin();
for ( ; cmdIt != cmds.end(); ++cmdIt ) {
const _pyID& objID = (*cmdIt)->GetObject();
if ( objID == hyp1dID ) {
- my1dHyp->Process( *cmdIt );
- my1dHyp->GetCreationCmd()->AddDependantCmd( *cmdIt );
+ if ( !hyp1d.IsNull() )
+ {
+ hyp1d->Process( *cmdIt );
+ hyp1d->GetCreationCmd()->AddDependantCmd( *cmdIt );
+ }
( *cmdIt )->SetObject( newName );
}
}
- // Set new hyp name to SetLayerDistribution() cmd
- if ( !myArgCommands.empty() && !myArgCommands.back()->IsEmpty() )
- myArgCommands.back()->SetArg( 1, newName );
+ // Set new hyp name to SetLayerDistribution(hyp1dID) cmd
+ (*cmd)->SetArg( 1, newName );
}
}
bool _pyNumberOfSegmentsHyp::Addition2Creation( const Handle(_pyCommand)& theCmd,
const _pyID& theMesh)
{
- if ( IsWrappable( theMesh ) && myArgs.Length() > 1 ) {
+ if ( IsWrappable( theMesh ) && myCurCrMethod->myArgs.size() > 1 ) {
// scale factor (2-nd arg) is provided: clear SetDistrType(1) command
bool scaleDistrType = false;
- list<Handle(_pyCommand)>::reverse_iterator cmd = myUnknownCommands.rbegin();
- for ( ; cmd != myUnknownCommands.rend(); ++cmd ) {
+ list<Handle(_pyCommand)>::reverse_iterator cmd = myUnusedCommands.rbegin();
+ for ( ; cmd != myUnusedCommands.rend(); ++cmd ) {
if ( (*cmd)->GetMethod() == "SetDistrType" ) {
if ( (*cmd)->GetArg( 1 ) == "1" ) {
scaleDistrType = true;
}
else if ( !scaleDistrType ) {
// distribution type changed: remove scale factor from args
- myArgs.Remove( 2, myArgs.Length() );
+ TType2CrMethod::iterator type2meth = myAlgoType2CreationMethod.begin();
+ for ( ; type2meth != myAlgoType2CreationMethod.end(); ++type2meth )
+ {
+ CreationMethod& crMethod = type2meth->second;
+ if ( crMethod.myArgs.size() == 2 )
+ crMethod.myArgs.pop_back();
+ }
break;
}
}
void _pyNumberOfSegmentsHyp::Flush()
{
// find number of the last SetDistrType() command
- list<Handle(_pyCommand)>::reverse_iterator cmd = myUnknownCommands.rbegin();
+ list<Handle(_pyCommand)>::reverse_iterator cmd = myUnusedCommands.rbegin();
int distrTypeNb = 0;
- for ( ; !distrTypeNb && cmd != myUnknownCommands.rend(); ++cmd )
+ for ( ; !distrTypeNb && cmd != myUnusedCommands.rend(); ++cmd )
if ( (*cmd)->GetMethod() == "SetDistrType" )
distrTypeNb = (*cmd)->GetOrderNb();
else if (IsWrapped() && (*cmd)->GetMethod() == "SetObjectEntry" )
(*cmd)->Clear();
// clear commands before the last SetDistrType()
- list<Handle(_pyCommand)> * cmds[2] = { &myArgCommands, &myUnknownCommands };
+ list<Handle(_pyCommand)> * cmds[2] = { &myArgCommands, &myUnusedCommands };
for ( int i = 0; i < 2; ++i ) {
set<TCollection_AsciiString> uniqueMethods;
list<Handle(_pyCommand)> & cmdList = *cmds[i];
theCmd->SetArg( 1, geom );
// set vertex as a second arg
- if ( myArgs.Length() < 1) myArgs.Append( "1" ); // :(
- myArgs.Append( vertex );
+ if ( myCurCrMethod->myArgs.size() < 1) setCreationArg( 1, "1" ); // :(
+ setCreationArg( 2, vertex );
// mesh.AddHypothesis(vertex, SegmentLengthAroundVertex) -->
// theMeshID.LengthNearVertex( length, vertex )
//================================================================================
/*!
* \brief Return substring of python command looking like
- * ResultValue1 , ResultValue1,... = Obj.Meth() with res index
+ * ResultValue1 , ResultValue2,... = Obj.Meth() with res index
* \retval const TCollection_AsciiString & - ResultValue with res index substring
*/
//================================================================================
-const TCollection_AsciiString & _pyCommand::GetResultValue(int res)
+TCollection_AsciiString _pyCommand::GetResultValue(int res)
{
int begPos = 1;
- int Nb=0;
+ if ( SkipSpaces( myString, begPos ) && myString.Value( begPos ) == '[' )
+ ++begPos; // skip [, else the whole list is returned
int endPos = myString.Location( "=", 1, Length() );
+ int Nb=0;
while ( begPos < endPos) {
- myRes = GetWord( myString, begPos, true );
- begPos = begPos + myRes.Length();
+ _AString result = GetWord( myString, begPos, true );
+ begPos = begPos + result.Length();
Nb++;
- if(res == Nb){
- myRes.RemoveAll('[');myRes.RemoveAll(']');
- return myRes;
+ if(res == Nb) {
+ result.RemoveAll('[');
+ result.RemoveAll(']');
+ return result;
}
if(Nb>res)
break;
if ( dotPos > begPos+myObj.Length() )
myObj = myString.SubString( begPos, dotPos-1 );
}
+ // 1st word after '=' is an object
+ // else // no method -> no object
+ // {
+ // myObj.Clear();
+ // begPos = EMPTY;
+ // }
// store
SetBegPos( OBJECT_IND, begPos );
}
if ( separatorStack.back().Location( chr, 1, separatorStack.back().Length()))
{
- if ( separatorStack.size() == 1 ) // ',' dividing args or a terminal ')' found
+ if ( separatorStack.size() == 1 ) // a comma dividing args or a terminal ')' found
{
while ( pos-1 >= prevPos && isspace( myString.Value( prevPos )))
++prevPos;
+ TCollection_AsciiString arg;
if ( pos-1 >= prevPos ) {
- TCollection_AsciiString arg = myString.SubString( prevPos, pos-1 );
+ arg = myString.SubString( prevPos, pos-1 );
arg.RightAdjust(); // remove spaces
arg.LeftAdjust();
+ }
+ if ( !arg.IsEmpty() || chr == ',' )
+ {
SetBegPos( ARG1_IND + myArgs.Length(), prevPos );
myArgs.Append( arg );
}
* \param theString - The string
* \param thePos - The position to search from and which returns result
* \retval bool - false if there are only space after thePos in theString
- *
- *
*/
//================================================================================
myCreator->GetCreationCmd()->AddDependantCmd( GetCreationCmd() );
}
+//================================================================================
+/*!
+ * \brief Creates _pyGroup
+ */
+//================================================================================
+
+_pyGroup::_pyGroup(const Handle(_pyCommand)& theCreationCmd, const _pyID & id)
+ :_pySubMesh(theCreationCmd)
+{
+ if ( !id.IsEmpty() )
+ setID( id );
+
+ myCanClearCreationCmd = true;
+
+ const _AString& method = theCreationCmd->GetMethod();
+ if ( method == "CreateGroup" ) // CreateGroup() --> CreateEmptyGroup()
+ {
+ theCreationCmd->SetMethod( "CreateEmptyGroup" );
+ }
+ // ----------------------------------------------------------------------
+ else if ( method == "CreateGroupFromGEOM" ) // (type, name, grp)
+ {
+ _pyID geom = theCreationCmd->GetArg( 3 );
+ // VSR 24/12/2010. PAL21106: always use GroupOnGeom() function on dump
+ // next if(){...} section is commented
+ //if ( sameGroupType( geom, theCreationCmd->GetArg( 1 )) ) { // --> Group(geom)
+ // theCreationCmd->SetMethod( "Group" );
+ // theCreationCmd->RemoveArgs();
+ // theCreationCmd->SetArg( 1, geom );
+ //}
+ //else {
+ // ------------------------->>>>> GroupOnGeom( geom, name, typ )
+ _pyID type = theCreationCmd->GetArg( 1 );
+ _pyID name = theCreationCmd->GetArg( 2 );
+ theCreationCmd->SetMethod( "GroupOnGeom" );
+ theCreationCmd->RemoveArgs();
+ theCreationCmd->SetArg( 1, geom );
+ theCreationCmd->SetArg( 2, name );
+ theCreationCmd->SetArg( 3, type );
+ //}
+ }
+ else if ( method == "CreateGroupFromFilter" )
+ {
+ // -> GroupOnFilter(typ, name, aFilter0x4743dc0 -> aFilter_1)
+ theCreationCmd->SetMethod( "GroupOnFilter" );
+
+ _pyID filterID = theCreationCmd->GetArg(3);
+ Handle(_pyFilter) filter = Handle(_pyFilter)::DownCast( theGen->FindObject( filterID ));
+ if ( !filter.IsNull())
+ {
+ if ( !filter->GetNewID().IsEmpty() )
+ theCreationCmd->SetArg( 3, filter->GetNewID() );
+ filter->AddUser( this );
+ }
+ myFilter = filter;
+ }
+ else
+ {
+ // theCreationCmd does something else apart from creation of this group
+ // and thus it can't be cleared if this group is removed
+ myCanClearCreationCmd = false;
+ }
+}
+
//================================================================================
/*!
* \brief To convert creation of a group by filter
_pyID idSource = theCommand->GetArg(1);
// check if idSource is a filter
filter = Handle(_pyFilter)::DownCast( theGen->FindObject( idSource ));
- if ( filter.IsNull() )
- return;
- // find aFilter.SetMesh(mesh) to clear it, it should be just before theCommand
- list< Handle(_pyCommand) >::reverse_iterator cmdIt = theGen->GetCommands().rbegin();
- while ( *cmdIt != theCommand ) ++cmdIt;
- while ( (*cmdIt)->GetOrderNb() != 1 )
+ if ( !filter.IsNull() )
{
- const Handle(_pyCommand)& setMeshCmd = *(++cmdIt);
- if ((setMeshCmd->GetObject() == idSource ||
- setMeshCmd->GetObject() == filter->GetNewID() )
- &&
- setMeshCmd->GetMethod() == "SetMesh")
+ // find aFilter.SetMesh(mesh) to clear it, it should be just before theCommand
+ list< Handle(_pyCommand) >::reverse_iterator cmdIt = theGen->GetCommands().rbegin();
+ while ( *cmdIt != theCommand ) ++cmdIt;
+ while ( (*cmdIt)->GetOrderNb() != 1 )
{
- setMeshCmd->Clear();
- break;
+ const Handle(_pyCommand)& setMeshCmd = *(++cmdIt);
+ if ((setMeshCmd->GetObject() == idSource ||
+ setMeshCmd->GetObject() == filter->GetNewID() )
+ &&
+ setMeshCmd->GetMethod() == "SetMesh")
+ {
+ setMeshCmd->Clear();
+ break;
+ }
}
+ // replace 3 commands by one
+ theCommand->Clear();
+ const Handle(_pyCommand)& makeGroupCmd = GetCreationCmd();
+ TCollection_AsciiString name = makeGroupCmd->GetArg( 2 );
+ if ( !filter->GetNewID().IsEmpty() )
+ idSource = filter->GetNewID();
+ makeGroupCmd->SetMethod( "MakeGroupByFilter" );
+ makeGroupCmd->SetArg( 1, name );
+ makeGroupCmd->SetArg( 2, idSource );
}
- // replace 3 commands by one
- theCommand->Clear();
- const Handle(_pyCommand)& makeGroupCmd = GetCreationCmd();
- TCollection_AsciiString name = makeGroupCmd->GetArg( 2 );
- makeGroupCmd->SetMethod( "MakeGroupByFilter" );
- makeGroupCmd->SetArg( 1, name );
- makeGroupCmd->SetArg( 2, idSource );
- // set new name of a filter
- filter->Process( makeGroupCmd );
}
else if ( theCommand->GetMethod() == "SetFilter" )
{
- // set new name of a filter
+ // set new name of a filter or clear the command if the same filter is set
_pyID filterID = theCommand->GetArg(1);
filter = Handle(_pyFilter)::DownCast( theGen->FindObject( filterID ));
- if ( !filter.IsNull() )
- filter->Process( theCommand );
+ if ( !myFilter.IsNull() && filter == myFilter )
+ theCommand->Clear();
+ else if ( !filter.IsNull() && !filter->GetNewID().IsEmpty() )
+ theCommand->SetArg( 1, filter->GetNewID() );
+ myFilter = filter;
+ }
+ else if ( theCommand->GetMethod() == "GetFilter" )
+ {
+ // GetFilter() returns a filter with other ID, make myFilter process
+ // calls of the returned filter
+ if ( !myFilter.IsNull() )
+ {
+ theGen->SetProxyObject( theCommand->GetResultValue(), myFilter );
+ theCommand->Clear();
+ }
}
if ( !filter.IsNull() )
filter->AddUser( this );
+
+ theGen->AddMeshAccessorMethod( theCommand );
+}
+
+//================================================================================
+/*!
+ * \brief Prevent clearing "DoubleNode...() command if a group created by it is removed
+ *
+ *
+ */
+//================================================================================
+
+void _pyGroup::Flush()
+{
+ if ( !theGen->IsToKeepAllCommands() &&
+ myCreationCmd && !myCanClearCreationCmd )
+ {
+ myCreationCmd.Nullify(); // this way myCreationCmd won't be cleared
+ }
}
//================================================================================
_pyObject::Process(theCommand); // count commands
if ( !myNewID.IsEmpty() )
- {
- if ( theCommand->GetObject() == GetID() )
- theCommand->SetObject( myNewID );
- else if ( theCommand->GetResultValue() == GetID() )
- theCommand->SetResultValue( myNewID );
- else
- for ( int i = 1, nb = theCommand->GetNbArgs(); i <= nb; ++i )
- if ( theCommand->GetArg( i ) == GetID() )
- {
- theCommand->SetArg( i, myNewID );
- break;
- }
- }
-
+ theCommand->SetObject( myNewID );
+
// Convert the following set of commands into smesh.GetFilterFromCriteria(criteria)
// aFilter0x2aaab0487080 = aFilterManager.CreateFilter()
// aFilter0x2aaab0487080.SetCriteria(aCriteria)
// Clear aFilterManager.CreateFilter()
GetCreationCmd()->Clear();
}
- else if ( theCommand->GetMethod() == "SetMesh")
+ else if ( theCommand->GetMethod() == "SetMesh" )
{
+ if ( myMesh == theCommand->GetArg( 1 ))
+ theCommand->Clear();
+ else
+ myMesh = theCommand->GetArg( 1 );
theGen->AddMeshAccessorMethod( theCommand );
}
}
return true;
}
+
+//================================================================================
+/*!
+ * \brief Reads _pyHypothesis'es from resource files of mesher Plugins
+ */
+//================================================================================
+
+_pyHypothesisReader::_pyHypothesisReader()
+{
+ // Get paths to xml files of plugins
+ vector< string > xmlPaths;
+ string sep;
+ if ( const char* meshersList = getenv("SMESH_MeshersList") )
+ {
+ string meshers = meshersList, plugin;
+ string::size_type from = 0, pos;
+ while ( from < meshers.size() )
+ {
+ // cut off plugin name
+ pos = meshers.find( ':', from );
+ if ( pos != string::npos )
+ plugin = meshers.substr( from, pos-from );
+ else
+ plugin = meshers.substr( from ), pos = meshers.size();
+ from = pos + 1;
+
+ // get PLUGIN_ROOT_DIR path
+ string rootDirVar, pluginSubDir = plugin;
+ if ( plugin == "StdMeshers" )
+ rootDirVar = "SMESH", pluginSubDir = "smesh";
+ else
+ for ( pos = 0; pos < plugin.size(); ++pos )
+ rootDirVar += toupper( plugin[pos] );
+ rootDirVar += "_ROOT_DIR";
+
+ const char* rootDir = getenv( rootDirVar.c_str() );
+ if ( !rootDir || strlen(rootDir) == 0 )
+ {
+ rootDirVar = plugin + "_ROOT_DIR"; // HexoticPLUGIN_ROOT_DIR
+ rootDir = getenv( rootDirVar.c_str() );
+ if ( !rootDir || strlen(rootDir) == 0 ) continue;
+ }
+
+ // get a separator from rootDir
+ for ( pos = strlen( rootDir )-1; pos >= 0 && sep.empty(); --pos )
+ if ( rootDir[pos] == '/' || rootDir[pos] == '\\' )
+ {
+ sep = rootDir[pos];
+ break;
+ }
+#ifdef WNT
+ if (sep.empty() ) sep = "\\";
+#else
+ if (sep.empty() ) sep = "/";
+#endif
+
+ // get a path to resource file
+ string xmlPath = rootDir;
+ if ( xmlPath[ xmlPath.size()-1 ] != sep[0] )
+ xmlPath += sep;
+ xmlPath += "share" + sep + "salome" + sep + "resources" + sep;
+ for ( pos = 0; pos < pluginSubDir.size(); ++pos )
+ xmlPath += tolower( pluginSubDir[pos] );
+ xmlPath += sep + plugin + ".xml";
+ bool fileOK;
+#ifdef WNT
+ fileOK = (GetFileAttributes(xmlPath.c_str()) != INVALID_FILE_ATTRIBUTES);
+#else
+ fileOK = (access(xmlPath.c_str(), F_OK) == 0);
+#endif
+ if ( fileOK )
+ xmlPaths.push_back( xmlPath );
+ }
+ }
+
+ // Read xml files
+ LDOMParser xmlParser;
+ for ( size_t i = 0; i < xmlPaths.size(); ++i )
+ {
+ bool error = xmlParser.parse( xmlPaths[i].c_str() );
+ if ( error )
+ {
+ _AString data;
+ INFOS( xmlParser.GetError(data) );
+ continue;
+ }
+ // <algorithm type="Regular_1D"
+ // label-id="Wire discretisation"
+ // ...>
+ // <python-wrap>
+ // <algo>Regular_1D=Segment()</algo>
+ // <hypo>LocalLength=LocalLength(SetLength(1),,SetPrecision(1))</hypo>
+ //
+ LDOM_Document xmlDoc = xmlParser.getDocument();
+ LDOM_NodeList algoNodeList = xmlDoc.getElementsByTagName( "algorithm" );
+ for ( int i = 0; i < algoNodeList.getLength(); ++i )
+ {
+ LDOM_Node algoNode = algoNodeList.item( i );
+ LDOM_Element& algoElem = (LDOM_Element&) algoNode;
+ LDOM_NodeList pyAlgoNodeList = algoElem.getElementsByTagName( "algo" );
+ if ( pyAlgoNodeList.getLength() < 1 ) continue;
+
+ _AString text, algoType, method, arg;
+ for ( int iA = 0; iA < pyAlgoNodeList.getLength(); ++iA )
+ {
+ LDOM_Node pyAlgoNode = pyAlgoNodeList.item( iA );
+ LDOM_Node textNode = pyAlgoNode.getFirstChild();
+ text = textNode.getNodeValue();
+ Handle(_pyCommand) algoCmd = new _pyCommand( text );
+ algoType = algoCmd->GetResultValue();
+ method = algoCmd->GetMethod();
+ arg = algoCmd->GetArg(1);
+ if ( !algoType.IsEmpty() && !method.IsEmpty() )
+ {
+ Handle(_pyAlgorithm) algo = new _pyAlgorithm( algoCmd );
+ algo->SetConvMethodAndType( method, algoType );
+ if ( !arg.IsEmpty() )
+ algo->setCreationArg( 1, arg );
+
+ myType2Hyp[ algoType ] = algo;
+ break;
+ }
+ }
+ if ( algoType.IsEmpty() ) continue;
+
+ LDOM_NodeList pyHypoNodeList = algoElem.getElementsByTagName( "hypo" );
+ _AString hypType;
+ Handle( _pyHypothesis ) hyp;
+ for ( int iH = 0; iH < pyHypoNodeList.getLength(); ++iH )
+ {
+ LDOM_Node pyHypoNode = pyHypoNodeList.item( iH );
+ LDOM_Node textNode = pyHypoNode.getFirstChild();
+ text = textNode.getNodeValue();
+ Handle(_pyCommand) hypoCmd = new _pyCommand( text );
+ hypType = hypoCmd->GetResultValue();
+ method = hypoCmd->GetMethod();
+ if ( !hypType.IsEmpty() && !method.IsEmpty() )
+ {
+ map<_AString, Handle(_pyHypothesis)>::iterator type2hyp = myType2Hyp.find( hypType );
+ if ( type2hyp == myType2Hyp.end() )
+ hyp = new _pyHypothesis( hypoCmd );
+ else
+ hyp = type2hyp->second;
+ hyp->SetConvMethodAndType( method, algoType );
+ for ( int iArg = 1; iArg <= hypoCmd->GetNbArgs(); ++iArg )
+ {
+ _pyCommand argCmd( hypoCmd->GetArg( iArg ));
+ _AString argMethod = argCmd.GetMethod();
+ _AString argNbText = argCmd.GetArg( 1 );
+ if ( argMethod.IsEmpty() && !argCmd.IsEmpty() )
+ hyp->setCreationArg( 1, argCmd.GetString() ); // e.g. Parameters(smesh.SIMPLE)
+ else
+ hyp->AddArgMethod( argMethod,
+ argNbText.IsIntegerValue() ? argNbText.IntegerValue() : 1 );
+ }
+ myType2Hyp[ hypType ] = hyp;
+ }
+ }
+ }
+ }
+}
+
+//================================================================================
+/*!
+ * \brief Returns a new hypothesis initialized according to the read information
+ */
+//================================================================================
+
+Handle(_pyHypothesis)
+_pyHypothesisReader::GetHypothesis(const _AString& hypType,
+ const Handle(_pyCommand)& creationCmd) const
+{
+ Handle(_pyHypothesis) resHyp, sampleHyp;
+
+ map<_AString, Handle(_pyHypothesis)>::const_iterator type2hyp = myType2Hyp.find( hypType );
+ if ( type2hyp != myType2Hyp.end() )
+ sampleHyp = type2hyp->second;
+
+ if ( sampleHyp.IsNull() )
+ {
+ resHyp = new _pyHypothesis(creationCmd);
+ }
+ else
+ {
+ if ( sampleHyp->IsAlgo() )
+ resHyp = new _pyAlgorithm( creationCmd );
+ else
+ resHyp = new _pyHypothesis(creationCmd);
+ resHyp->Assign( sampleHyp, _pyID() );
+ }
+ return resHyp;
+}