]> SALOME platform Git repositories - modules/smesh.git/blobdiff - src/SMESH_I/SMESH_MeshEditor_i.cxx
Salome HOME
Fix of the problem with vtkRenderer::GetActors() method
[modules/smesh.git] / src / SMESH_I / SMESH_MeshEditor_i.cxx
index 8fb61b896e89eafb46c63975dcc108759f014239..428aacbc94226da6a95b418ae3270d0fb4d239d8 100644 (file)
@@ -26,6 +26,7 @@
 
 #include "SMESH_MeshEditor_i.hxx"
 
+#include "SMDS_Mesh0DElement.hxx"
 #include "SMDS_MeshEdge.hxx"
 #include "SMDS_MeshFace.hxx"
 #include "SMDS_MeshVolume.hxx"
@@ -34,6 +35,8 @@
 #include "SMESH_subMeshEventListener.hxx"
 #include "SMESH_Gen_i.hxx"
 #include "SMESH_Filter_i.hxx"
+#include "SMESH_subMesh_i.hxx"
+#include "SMESH_Group_i.hxx"
 #include "SMESH_PythonDump.hxx"
 
 #include "utilities.h"
@@ -80,7 +83,7 @@ namespace {
     SMDSAbs_ElementType myPreviewType; // type to show
     //!< Constructor
     TPreviewMesh(SMDSAbs_ElementType previewElements = SMDSAbs_All) {
-      _isShapeToMesh = _id =_studyId =_idDoc = 0;
+      _isShapeToMesh = (_id =_studyId =_idDoc = 0);
       _myMeshDS  = new SMESHDS_Mesh( _id, true );
       myPreviewType = previewElements;
     }
@@ -199,6 +202,7 @@ namespace {
         for (sm = subMeshes.begin(); sm != subMeshes.end(); sm++)
           sm->second->DeleteEventListener( this );
       }
+      myMesh = 0;
     }
   };
 
@@ -316,6 +320,47 @@ CORBA::Boolean SMESH_MeshEditor_i::RemoveNodes(const SMESH::long_array & IDsOfNo
  */
 //=============================================================================
 
+CORBA::Long SMESH_MeshEditor_i::AddNode(CORBA::Double x,
+                                        CORBA::Double y, CORBA::Double z)
+{
+  initData();
+
+  const SMDS_MeshNode* N = GetMeshDS()->AddNode(x, y, z);
+
+  // Update Python script
+  TPythonDump() << "nodeID = " << this << ".AddNode( "
+                << x << ", " << y << ", " << z << " )";
+
+  return N->GetID();
+}
+
+//=============================================================================
+/*!
+ *
+ */
+//=============================================================================
+CORBA::Long SMESH_MeshEditor_i::Add0DElement(CORBA::Long IDOfNode)
+{
+  initData();
+
+  const SMDS_MeshNode* aNode = GetMeshDS()->FindNode(IDOfNode);
+  SMDS_MeshElement* elem = GetMeshDS()->Add0DElement(aNode);
+
+  // Update Python script
+  TPythonDump() << "elem0d = " << this << ".Add0DElement( " << IDOfNode <<" )";
+
+  if (elem)
+    return elem->GetID();
+
+  return 0;
+}
+
+//=============================================================================
+/*!
+ *
+ */
+//=============================================================================
+
 CORBA::Long SMESH_MeshEditor_i::AddEdge(const SMESH::long_array & IDsOfNodes)
 {
   initData();
@@ -350,26 +395,6 @@ CORBA::Long SMESH_MeshEditor_i::AddEdge(const SMESH::long_array & IDsOfNodes)
   return 0;
 }
 
-//=============================================================================
-/*!
- *
- */
-//=============================================================================
-
-CORBA::Long SMESH_MeshEditor_i::AddNode(CORBA::Double x,
-                                        CORBA::Double y, CORBA::Double z)
-{
-  initData();
-
-  const SMDS_MeshNode* N = GetMeshDS()->AddNode(x, y, z);
-
-  // Update Python script
-  TPythonDump() << "nodeID = " << this << ".AddNode( "
-                << x << ", " << y << ", " << z << " )";
-
-  return N->GetID();
-}
-
 //=============================================================================
 /*!
  *  AddFace
@@ -1995,7 +2020,7 @@ SMESH_MeshEditor_i::extrusionAlongPath(const SMESH::long_array &   theIDsOfEleme
   ::SMESH_MeshEditor anEditor( myMesh );
   ::SMESH_MeshEditor::Extrusion_Error error =
       anEditor.ExtrusionAlongTrack( elements, aSubMesh, nodeStart,
-                                    theHasAngles, angles,
+                                    theHasAngles, angles, false,
                                     theHasRefPoint, refPnt, theMakeGroups );
   storeResult(anEditor);
   theError = convExtrError( error );
@@ -2010,6 +2035,105 @@ SMESH_MeshEditor_i::extrusionAlongPath(const SMESH::long_array &   theIDsOfEleme
   return 0;
 }
 
+
+//=======================================================================
+//function : extrusionAlongPathX
+//purpose  : 
+//=======================================================================
+
+SMESH::ListOfGroups*
+SMESH_MeshEditor_i::extrusionAlongPathX(const SMESH::long_array &  IDsOfElements,
+                                       SMESH::SMESH_IDSource_ptr  Path,
+                                       CORBA::Long                NodeStart,
+                                       CORBA::Boolean             HasAngles,
+                                       const SMESH::double_array& Angles,
+                                       CORBA::Boolean             LinearVariation,
+                                       CORBA::Boolean             HasRefPoint,
+                                       const SMESH::PointStruct&  RefPoint,
+                                       const bool                 MakeGroups,
+                                       const SMDSAbs_ElementType  ElementType,
+                                       SMESH::SMESH_MeshEditor::Extrusion_Error & Error)
+{
+  SMESH::ListOfGroups* EmptyGr = new SMESH::ListOfGroups;
+
+  initData();
+
+  list<double> angles;
+  for (int i = 0; i < Angles.length(); i++) {
+    angles.push_back( Angles[i] );
+  }
+  gp_Pnt refPnt( RefPoint.x, RefPoint.y, RefPoint.z );
+  int nbOldGroups = myMesh->NbGroup();
+
+  if ( Path->_is_nil() ) {
+    Error = SMESH::SMESH_MeshEditor::EXTR_BAD_PATH_SHAPE;
+    return EmptyGr;
+  }
+
+  TIDSortedElemSet elements;
+  arrayToSet(IDsOfElements, GetMeshDS(), elements, ElementType);
+
+  ::SMESH_MeshEditor anEditor( myMesh );
+  ::SMESH_MeshEditor::Extrusion_Error error;
+
+  SMESH_Mesh_i* aMeshImp = SMESH::DownCast<SMESH_Mesh_i*>( Path );
+  if(aMeshImp) {
+    // path as mesh
+    SMDS_MeshNode* aNodeStart = 
+      (SMDS_MeshNode*)aMeshImp->GetImpl().GetMeshDS()->FindNode(NodeStart);
+    if ( !aNodeStart ) {
+      Error = SMESH::SMESH_MeshEditor::EXTR_BAD_STARTING_NODE;
+      return EmptyGr;
+    }
+    error = anEditor.ExtrusionAlongTrack( elements, &(aMeshImp->GetImpl()), aNodeStart,
+                                         HasAngles, angles, LinearVariation,
+                                         HasRefPoint, refPnt, MakeGroups );
+  }
+  else {
+    SMESH_subMesh_i* aSubMeshImp = SMESH::DownCast<SMESH_subMesh_i*>( Path );
+    if(aSubMeshImp) {
+      // path as submesh
+      SMESH::SMESH_Mesh_ptr aPathMesh = aSubMeshImp->GetFather();
+      aMeshImp = SMESH::DownCast<SMESH_Mesh_i*>( aPathMesh );
+      SMDS_MeshNode* aNodeStart = 
+       (SMDS_MeshNode*)aMeshImp->GetImpl().GetMeshDS()->FindNode(NodeStart);
+      if ( !aNodeStart ) {
+       Error = SMESH::SMESH_MeshEditor::EXTR_BAD_STARTING_NODE;
+       return EmptyGr;
+      }
+      SMESH_subMesh* aSubMesh = 
+       aMeshImp->GetImpl().GetSubMeshContaining(aSubMeshImp->GetId());
+      error = anEditor.ExtrusionAlongTrack( elements, aSubMesh, aNodeStart,
+                                           HasAngles, angles, LinearVariation,
+                                           HasRefPoint, refPnt, MakeGroups );
+    }
+    else {
+      SMESH_Group_i* aGroupImp = SMESH::DownCast<SMESH_Group_i*>( Path );
+      if(aGroupImp) {
+       // path as group of 1D elements
+      }
+      else {
+       // invalid path
+       Error = SMESH::SMESH_MeshEditor::EXTR_BAD_PATH_SHAPE;
+       return EmptyGr;
+      }
+    }
+  }
+
+  storeResult(anEditor);
+  Error = convExtrError( error );
+
+  if ( MakeGroups ) {
+    list<int> groupIDs = myMesh->GetGroupIds();
+    list<int>::iterator newBegin = groupIDs.begin();
+    std::advance( newBegin, nbOldGroups ); // skip old groups
+    groupIDs.erase( groupIDs.begin(), newBegin );
+    return getGroups( & groupIDs );
+  }
+  return EmptyGr;
+}
+
+
 //=======================================================================
 //function : ExtrusionAlongPath
 //purpose  :
@@ -2408,6 +2532,124 @@ ExtrusionAlongPathObject2DMakeGroups(SMESH::SMESH_IDSource_ptr  theObject,
   return aGroups;
 }
 
+
+//=======================================================================
+//function : ExtrusionAlongPathObjX
+//purpose  : 
+//=======================================================================
+SMESH::ListOfGroups* SMESH_MeshEditor_i::
+ExtrusionAlongPathObjX(SMESH::SMESH_IDSource_ptr  Object,
+                      SMESH::SMESH_IDSource_ptr  Path,
+                      CORBA::Long                NodeStart,
+                      CORBA::Boolean             HasAngles,
+                      const SMESH::double_array& Angles,
+                      CORBA::Boolean             LinearVariation,
+                      CORBA::Boolean             HasRefPoint,
+                      const SMESH::PointStruct&  RefPoint,
+                      CORBA::Boolean             MakeGroups,
+                      SMESH::ElementType         ElemType,
+                      SMESH::SMESH_MeshEditor::Extrusion_Error& Error)
+{
+  SMESH::long_array_var anElementsId = Object->GetIDs();
+  SMESH::ListOfGroups * aGroups = extrusionAlongPathX(anElementsId,
+                                                     Path,
+                                                     NodeStart,
+                                                     HasAngles,
+                                                     Angles,
+                                                     LinearVariation,
+                                                     HasRefPoint,
+                                                     RefPoint,
+                                                     MakeGroups,
+                                                     (SMDSAbs_ElementType)ElemType,
+                                                     Error);
+  
+  if ( !myPreviewMode ) {
+    bool isDumpGroups = aGroups && aGroups->length() > 0;
+    TPythonDump aPythonDump;
+    if(isDumpGroups) {
+      aPythonDump << "("<<aGroups;
+    }
+    if(isDumpGroups)
+      aPythonDump << ", error)";
+    else
+      aPythonDump <<"error";
+
+    aPythonDump << " = " << this << ".ExtrusionAlongPathObjX( "
+                << Object      << ", "
+                << Path        << ", "
+                << NodeStart   << ", "
+                << HasAngles   << ", "
+                << Angles      << ", "
+               << LinearVariation << ", "
+               << HasRefPoint << ", "
+               << "SMESH.PointStruct( "
+               << ( HasRefPoint ? RefPoint.x : 0 ) << ", "
+               << ( HasRefPoint ? RefPoint.y : 0 ) << ", "
+               << ( HasRefPoint ? RefPoint.z : 0 ) << " ), "
+               << ElemType << " )";
+  }
+  return aGroups;
+}
+
+
+//=======================================================================
+//function : ExtrusionAlongPathX
+//purpose  : 
+//=======================================================================
+SMESH::ListOfGroups* SMESH_MeshEditor_i::
+ExtrusionAlongPathX(const SMESH::long_array&   IDsOfElements,
+                   SMESH::SMESH_IDSource_ptr  Path,
+                   CORBA::Long                NodeStart,
+                   CORBA::Boolean             HasAngles,
+                   const SMESH::double_array& Angles,
+                   CORBA::Boolean             LinearVariation,
+                   CORBA::Boolean             HasRefPoint,
+                   const SMESH::PointStruct&  RefPoint,
+                   CORBA::Boolean             MakeGroups,
+                   SMESH::ElementType         ElemType,
+                   SMESH::SMESH_MeshEditor::Extrusion_Error& Error)
+{
+  SMESH::ListOfGroups * aGroups = extrusionAlongPathX(IDsOfElements,
+                                                     Path,
+                                                     NodeStart,
+                                                     HasAngles,
+                                                     Angles,
+                                                     LinearVariation,
+                                                     HasRefPoint,
+                                                     RefPoint,
+                                                     MakeGroups,
+                                                     (SMDSAbs_ElementType)ElemType,
+                                                     Error);
+  
+  if ( !myPreviewMode ) {
+    bool isDumpGroups = aGroups && aGroups->length() > 0;
+    TPythonDump aPythonDump;
+    if(isDumpGroups) {
+      aPythonDump << "("<<aGroups;
+    }
+    if(isDumpGroups)
+      aPythonDump << ", error)";
+    else
+      aPythonDump <<"error";
+
+    aPythonDump << " = " << this << ".ExtrusionAlongPathX( "
+                << IDsOfElements << ", "
+                << Path        << ", "
+                << NodeStart   << ", "
+                << HasAngles   << ", "
+                << Angles      << ", "
+               << LinearVariation << ", "
+               << HasRefPoint << ", "
+               << "SMESH.PointStruct( "
+               << ( HasRefPoint ? RefPoint.x : 0 ) << ", "
+               << ( HasRefPoint ? RefPoint.y : 0 ) << ", "
+               << ( HasRefPoint ? RefPoint.z : 0 ) << " ), "
+               << ElemType << " )";
+  }
+  return aGroups;
+}
+
+
 //================================================================================
 /*!
  * \brief Compute rotation angles for ExtrusionAlongPath as linear variation
@@ -3874,11 +4116,7 @@ SMESH::SMESH_Mesh_ptr SMESH_MeshEditor_i::makeMesh(const char* theMeshName)
   SALOMEDS::Study_var study = gen->GetCurrentStudy();
   SALOMEDS::SObject_var meshSO = gen->ObjectToSObject( study, mesh );
   gen->SetName( meshSO, theMeshName, "Mesh" );
-
-  SALOMEDS::StudyBuilder_var builder = study->NewBuilder();
-  SALOMEDS::GenericAttribute_var anAttr
-    = builder->FindOrCreateAttribute( meshSO, "AttributePixMap" );
-  SALOMEDS::AttributePixMap::_narrow( anAttr )->SetPixMap( "ICON_SMESH_TREE_MESH_IMPORTED" );
+  gen->SetPixMap( meshSO, "ICON_SMESH_TREE_MESH_IMPORTED");
 
   return mesh._retn();
 }