Salome HOME
IPAL19834: Incorrect result after make Partition of 2 objects. A fix by PKV.
[modules/geom.git] / src / BasicGUI / BasicGUI_CurveDlg.cxx
index e8255f369c8cd483b51759bf39f72f54b4b0ce3e..a3e278ad1759f7ab3ae38ac4432f5ad960647de9 100644 (file)
 
 #include "BasicGUI_CurveDlg.h"
 
-#include <GEOM_DlgRef.h>
+#include <DlgRef.h>
 #include <GeometryGUI.h>
 #include <GEOMBase.h>
 
 #include <SUIT_ResourceMgr.h>
 #include <SUIT_Session.h>
 #include <SalomeApp_Application.h>
+#include <SalomeApp_Study.h>
 #include <LightApp_SelectionMgr.h>
 
 #include <SALOME_ListIteratorOfListIO.hxx>
 #include <SALOME_ListIO.hxx>
 
+#include <TopoDS_Shape.hxx>
+#include <TopoDS.hxx>
+#include <TopExp.hxx>
+#include <TColStd_IndexedMapOfInteger.hxx>
+#include <TopTools_IndexedMapOfShape.hxx>
+
 #include <GEOMImpl_Types.hxx>
 
 //=================================================================================
@@ -47,7 +54,7 @@
 //=================================================================================
 BasicGUI_CurveDlg::BasicGUI_CurveDlg( GeometryGUI* theGeometryGUI, QWidget* parent,
                                      bool modal, Qt::WindowFlags fl )
-  : GEOMBase_Skeleton( theGeometryGUI, parent, "BasicGUI_CurveDlg", modal, fl )
+  : GEOMBase_Skeleton( theGeometryGUI, parent, modal, fl )
 {
   QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_POLYLINE" ) ) );
   QPixmap image2( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_SPLINE" ) ) );
@@ -74,7 +81,7 @@ BasicGUI_CurveDlg::BasicGUI_CurveDlg( GeometryGUI* theGeometryGUI, QWidget* pare
   layout->addWidget( GroupPoints );
   /***************************************************************/
 
-  setHelpFileName( "curve.htm" );
+  setHelpFileName( "create_curve_page.html" );
 
   Init();
 }
@@ -101,7 +108,8 @@ void BasicGUI_CurveDlg::Init()
   myPoints = new GEOM::ListOfGO();
   myPoints->length( 0 );
 
-  globalSelection( GEOM_POINT );
+  globalSelection(); // close local contexts, if any
+  localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
 
   /* signals and slots connections */
   connect( myGeomGUI, SIGNAL( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog( ) ) );
@@ -115,9 +123,9 @@ void BasicGUI_CurveDlg::Init()
   connect( GroupPoints->PushButton1, SIGNAL( clicked() ),       this, SLOT( SetEditCurrentArgument() ) );
   connect( GroupPoints->LineEdit1,   SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
 
-  connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(), 
-          SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
-
+  connect( myGeomGUI->getApp()->selectionMgr(), 
+          SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) ) ;
   initName( tr( "GEOM_CURVE" ) );
   ConstructorsClicked( 0 );
 }
@@ -184,7 +192,8 @@ bool BasicGUI_CurveDlg::ClickOnApply()
     return false;
 
   initName();
-  ConstructorsClicked( getConstructorId() );
+  globalSelection(); // close local contexts, if any
+  localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
   return true;
 }
 
@@ -195,7 +204,7 @@ bool BasicGUI_CurveDlg::ClickOnApply()
  * \retval -1, if point not in list, else 1 in list
  */
 //=================================================================================
-static int isPointInList( list<GEOM::GEOM_Object_var>& thePoints,
+static int isPointInList( std::list<GEOM::GEOM_Object_var>& thePoints,
                          GEOM::GEOM_Object_var& theObject )
 {
   int len = thePoints.size();
@@ -204,8 +213,8 @@ static int isPointInList( list<GEOM::GEOM_Object_var>& thePoints,
     return -1;
   }
   
-  for ( list<GEOM::GEOM_Object_var>::iterator i = thePoints.begin(); i != thePoints.end(); i++ ) {
-    if ( string( (*i)->GetEntry() ) == string( theObject->GetEntry() ) ) {
+  for ( std::list<GEOM::GEOM_Object_var>::iterator i = thePoints.begin(); i != thePoints.end(); i++ ) {
+    if ( std::string( (*i)->GetEntry() ) == std::string( theObject->GetEntry() ) ) {
       return 1;
     }
   }
@@ -220,14 +229,14 @@ static int isPointInList( list<GEOM::GEOM_Object_var>& thePoints,
  * \li \a theNewPoints - not ordered sequence with necessary points
  */
 //=================================================================================
-static void removeUnnecessaryPnt( list<GEOM::GEOM_Object_var>& theOldPoints,
+static void removeUnnecessaryPnt( std::list<GEOM::GEOM_Object_var>& theOldPoints,
                                  GEOM::ListOfGO_var& theNewPoints )
 {
-  list<GEOM::GEOM_Object_var> objs_to_remove;
-  for ( list<GEOM::GEOM_Object_var>::iterator i = theOldPoints.begin(); i != theOldPoints.end(); i++ ) {
+  std::list<GEOM::GEOM_Object_var> objs_to_remove;
+  for ( std::list<GEOM::GEOM_Object_var>::iterator i = theOldPoints.begin(); i != theOldPoints.end(); i++ ) {
     bool found = false;
     for ( int j = 0; j < theNewPoints->length() && !found ; j++ ) {
-      if ( string( (*i)->GetEntry() ) == string( theNewPoints[j]->GetEntry() ) ) {
+      if ( std::string( (*i)->GetEntry() ) == std::string( theNewPoints[j]->GetEntry() ) ) {
        found = true;
       }
     }
@@ -236,7 +245,7 @@ static void removeUnnecessaryPnt( list<GEOM::GEOM_Object_var>& theOldPoints,
       //cout << "removed: " << (*i)->GetEntry() << endl;
     }
   }
-  for ( list<GEOM::GEOM_Object_var>::iterator i = objs_to_remove.begin(); i != objs_to_remove.end(); i++ ) {
+  for ( std::list<GEOM::GEOM_Object_var>::iterator i = objs_to_remove.begin(); i != objs_to_remove.end(); i++ ) {
     theOldPoints.remove( *i );
   }
 }
@@ -250,41 +259,97 @@ void BasicGUI_CurveDlg::SelectionIntoArgument()
   myEditCurrentArgument->setText( "" );
 
   Standard_Boolean aRes = Standard_False;
-  int i = 0;
+
   int IOC = IObjectCount();
-  bool is_append = myPoints->length() < IOC; // if true - add point, else remove
-  myPoints->length( IOC ); // this length may be greater than number of objects,
+  // bool is_append = myPoints->length() < IOC; // if true - add point, else remove
+  // myPoints->length( IOC ); // this length may be greater than number of objects,
                            // that will actually be put into myPoints
-  for ( SALOME_ListIteratorOfListIO anIt( selectedIO() ); anIt.More(); anIt.Next() ) {
+
+  LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
+  SalomeApp_Application* app =
+    dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
+  SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
+  _PTR(Study) aDStudy = appStudy->studyDS();
+  GEOM::GEOM_IShapesOperations_var aShapesOp = getGeomEngine()->GetIShapesOperations( getStudyId() );
+
+  int anIndex;
+  TopoDS_Shape aShape;
+  TColStd_IndexedMapOfInteger aMapIndexes;
+  GEOM::GEOM_Object_var anObject;
+  std::list<GEOM::GEOM_Object_var> aList;
+  SALOME_ListIO selected;
+  aSelMgr->selectedObjects( selected, QString::null, false );
+  
+  for ( SALOME_ListIteratorOfListIO anIt( selected ); anIt.More(); anIt.Next() ) {
     GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( anIt.Value(), aRes );
     if ( !CORBA::is_nil( aSelectedObject ) && aRes ) {
-      //TopoDS_Shape aPointShape;
-      //if ( myGeomBase->GetShape( aSelectedObject, aPointShape, TopAbs_VERTEX ) )
-      int pos = isPointInList(myOrderedSel, aSelectedObject);
-      if ( is_append && pos == -1 )
-       myOrderedSel.push_back( aSelectedObject );
-      myPoints[i++] = aSelectedObject;
+      if ( GEOMBase::GetShape( aSelectedObject, aShape, TopAbs_SHAPE ) && !aShape.IsNull() ) {
+       aSelMgr->GetIndexes( anIt.Value(), aMapIndexes );
+       
+       if ( aMapIndexes.Extent() > 0 ) {
+         for ( int ii = 1; ii <= aMapIndexes.Extent(); ii++ ) {
+           anIndex = aMapIndexes(ii);
+           QString aName = GEOMBase::GetName( aSelectedObject );
+           aName = aName + ":vertex_" + QString::number( anIndex );
+           anObject = aShapesOp->GetSubShape( aSelectedObject, anIndex );
+           //Find Object in study
+           _PTR(SObject) obj ( aDStudy->FindObjectID( anIt.Value()->getEntry() ) );
+           bool inStudy = false;
+            _PTR(ChildIterator) iit( aDStudy->NewChildIterator( obj ) );
+            for (; iit->More() && !inStudy; iit->Next()) {
+             _PTR(SObject) child( iit->Value() );
+             QString aChildName = child->GetName().c_str();
+             if ( aChildName == aName ) {
+               inStudy = true;
+               CORBA::Object_var corbaObj = GeometryGUI::ClientSObjectToObject( iit->Value() );
+               anObject = GEOM::GEOM_Object::_narrow( corbaObj );
+             }
+           }
+           
+           if ( !inStudy )
+             GeometryGUI::GetGeomGen()->AddInStudy( GeometryGUI::ClientStudyToStudy( aDStudy ),
+                                                    anObject, aName.toLatin1().data(), aSelectedObject );
+           
+           int pos = isPointInList( myOrderedSel, anObject );
+           if ( pos == -1 ) {
+             myOrderedSel.push_back( anObject );
+           }
+           //              if (!inStudy)
+           aList.push_back(anObject);
+         }
+       } 
+       else { // aMap.Extent() == 0
+         int pos = isPointInList( myOrderedSel, aSelectedObject );
+         if ( pos == -1 )
+           myOrderedSel.push_back( aSelectedObject );
+         aList.push_back( aSelectedObject );
+       } 
+      }
     }
   }
   
-  myPoints->length( i ); // this is the right length, smaller of equal to the previously set
+  myPoints->length( aList.size()  );  
+
+  int k = 0;
+  for ( std::list<GEOM::GEOM_Object_var>::iterator j = aList.begin(); j != aList.end(); j++ )
+    myPoints[k++] = *j;
+
   if ( IOC == 0 )
     myOrderedSel.clear();
   else
     removeUnnecessaryPnt( myOrderedSel, myPoints );
 
-  if ( myOrderedSel.size() == myPoints->length() ) {
-    int k = 0;
-    for ( list<GEOM::GEOM_Object_var>::iterator j = myOrderedSel.begin(); j!= myOrderedSel.end(); j++ )
-      myPoints[k++] = *j;
-  } 
-  else {
-    //cout << "ERROR: Ordered sequence size != selection sequence size! ("<<myOrderedSel.size()<<"!="<<myPoints->length()<<")"<<endl;
-  }
-  if ( i )
-    GroupPoints->LineEdit1->setText( QString::number( i ) + "_" + tr( "GEOM_POINT" ) + tr( "_S_" ) );
-  
-  displayPreview(); 
+  // if ( myOrderedSel.size() == myPoints->length() ) {
+  myPoints->length( myOrderedSel.size()  );  
+  k = 0;
+  for ( std::list<GEOM::GEOM_Object_var>::iterator j = myOrderedSel.begin(); j != myOrderedSel.end(); j++ )
+    myPoints[k++] = *j;
+  //  }
+
+  if ( myPoints->length() > 0  )
+    GroupPoints->LineEdit1->setText( QString::number( myPoints->length() ) + "_" + tr( "GEOM_POINT" ) + tr( "_S_" ) );
+   
+displayPreview(); 
 }
 
 
@@ -295,12 +360,12 @@ void BasicGUI_CurveDlg::SelectionIntoArgument()
 void BasicGUI_CurveDlg::ActivateThisDialog()
 {
   GEOMBase_Skeleton::ActivateThisDialog();
-  connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(), 
-          SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
+  connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
+          this, SLOT( SelectionIntoArgument() ) );
 
-  // myGeomGUI->SetState( 0 );
+  globalSelection(); // close local contexts, if any
+  localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
 
-  globalSelection( GEOM_POINT );
   ConstructorsClicked( getConstructorId() );
 }
 
@@ -372,13 +437,3 @@ bool BasicGUI_CurveDlg::execute( ObjectList& objects )
 
   return res;
 }
-
-//=================================================================================
-// function : closeEvent
-// purpose  :
-//=================================================================================
-void BasicGUI_CurveDlg::closeEvent( QCloseEvent* e )
-{
-  GEOMBase_Skeleton::closeEvent( e );
-}
-