Salome HOME
NPAL 18378
[modules/geom.git] / src / GEOMBase / GEOMBase_Helper.cxx
index 460b77b528778969ac6c7fcdfad6946952fb86c7..95ff8f0ec06fca07cac5848950a7bc97519ce146 100755 (executable)
@@ -44,6 +44,7 @@
 #include <SalomeApp_Application.h>
 #include <SalomeApp_Study.h>
 #include <LightApp_SelectionMgr.h>
+#include <LightApp_DataOwner.h>
 #include <SalomeApp_Tools.h>
 #include <SalomeApp_DataModel.h>
 
@@ -247,7 +248,9 @@ void GEOMBase_Helper::redisplay( GEOM::GEOM_Object_ptr object,
 void GEOMBase_Helper::displayPreview( const bool   activate,
                                       const bool   update,
                                       const bool   toRemoveFromEngine,
-                                      const double lineWidth )
+                                      const double lineWidth, 
+                                      const int    displayMode, 
+                                      const int    color )
 {
   isPreview = true;
   QString msg;
@@ -269,7 +272,7 @@ void GEOMBase_Helper::displayPreview( const bool   activate,
     else {
       for ( ObjectList::iterator it = objects.begin(); it != objects.end(); ++it )
       {
-        displayPreview( *it, true, activate, false, lineWidth );
+        displayPreview( *it, true, activate, false, lineWidth, displayMode, color );
         if ( toRemoveFromEngine )
           getGeomEngine()->RemoveObject( *it );
       }
@@ -293,13 +296,18 @@ void GEOMBase_Helper::displayPreview( GEOM::GEOM_Object_ptr object,
                                       const bool            append,
                                       const bool            activate,
                                       const bool            update,
-                                      const double          lineWidth )
+                                      const double          lineWidth, 
+                                      const int             displayMode, 
+                                      const int             color )
 {
   // Set color for preview shape
-  getDisplayer()->SetColor( Quantity_NOC_VIOLET );
+  getDisplayer()->SetColor( color == -1 ? Quantity_NOC_VIOLET : color );
 
   // set width of displayed shape
   getDisplayer()->SetWidth( lineWidth );
+  
+  // set display mode of displayed shape
+  int aPrevDispMode = getDisplayer()->SetDisplayMode( displayMode );
 
   // Disable activation of selection
   getDisplayer()->SetToActivate( activate );
@@ -316,6 +324,8 @@ void GEOMBase_Helper::displayPreview( GEOM::GEOM_Object_ptr object,
   displayPreview( aPrs, append, update );
 
   getDisplayer()->UnsetName();
+  getDisplayer()->UnsetColor();
+  getDisplayer()->SetDisplayMode( aPrevDispMode );
 
   // Enable activation of displayed objects
   getDisplayer()->SetToActivate( true );
@@ -760,6 +770,7 @@ bool GEOMBase_Helper::onAccept( const bool publish, const bool useTransaction )
        showError();
       }
       else {
+       addSubshapesToStudy(); // add Subshapes if local selection
        const int nbObjs = objects.size();
         int aNumber = 1;
        for ( ObjectList::iterator it = objects.begin(); it != objects.end(); ++it ) {
@@ -985,3 +996,104 @@ SUIT_Desktop* GEOMBase_Helper::getDesktop() const
   return myDesktop;
 }
 
+//================================================================
+// Function : selectObjects
+// Purpose  : Selects list of objects 
+//================================================================
+bool GEOMBase_Helper::selectObjects( ObjectList& objects )
+{
+  SUIT_DataOwnerPtrList aList;
+  ObjectList::iterator anIter;
+  for ( anIter = objects.begin(); anIter != objects.end(); ++anIter )
+  {
+    string entry = getEntry( *anIter );
+    QString aEntry( entry.c_str() );
+    LightApp_DataOwner* anOwher = new LightApp_DataOwner( aEntry );
+    aList.append( anOwher );
+  }
+  
+  SUIT_Session* session = SUIT_Session::session();
+  SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
+  if ( !app )
+    return false;
+
+  LightApp_SelectionMgr* aMgr = app->selectionMgr();
+  if ( !aMgr )
+    return false;
+  
+  aMgr->setSelected( aList, false );
+  
+  return true;
+}
+  
+//================================================================
+// Function : findObjectInFather
+// Purpose  : It should return an object if its founded in study or
+//            return Null object if the object is not founded
+//================================================================
+GEOM::GEOM_Object_ptr GEOMBase_Helper::findObjectInFather( GEOM::GEOM_Object_ptr theFather, const char* theName)
+{
+  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();
+  string IOR = GEOMBase::GetIORFromObject( theFather );
+  _PTR(SObject) SObj ( aDStudy->FindObjectIOR( IOR ) );
+
+  bool inStudy = false;
+  GEOM::GEOM_Object_var aReturnObject;
+  for (_PTR(ChildIterator) iit (aDStudy->NewChildIterator( SObj )); iit->More(); iit->Next()) {
+    _PTR(SObject) child (iit->Value());
+    QString aChildName = child->GetName();
+    if (aChildName == theName) {
+      inStudy = true;
+      CORBA::Object_var corbaObj = GeometryGUI::ClientSObjectToObject(iit->Value());
+      aReturnObject = GEOM::GEOM_Object::_narrow( corbaObj );
+    }
+  }
+  if (!inStudy)
+    return GEOM::GEOM_Object::_nil();
+  else
+    return aReturnObject._retn();
+}
+  
+//================================================================
+// Function : addSubshapesToStudy
+// Purpose  : Virtual method to add subshapes if needs
+//================================================================  
+void GEOMBase_Helper::addSubshapesToStudy()
+{
+  //Impemented in Dialogs, called from Accept method
+}
+
+//================================================================
+// Function : addSubshapesToFather
+// Purpose  : Method to add Father Subshapes to Study if it`s not exist
+//================================================================  
+void GEOMBase_Helper::addSubshapesToFather( QMap<QString, GEOM::GEOM_Object_var>& theMap )
+{
+  //GetStudyDS
+  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_IGroupOperations_var anOp = getGeomEngine()->GetIGroupOperations( getStudyId() );
+  for( QMap<QString, GEOM::GEOM_Object_var>::Iterator it = theMap.begin(); it != theMap.end(); it++ )
+    {
+      if ( !anOp->_is_nil() ) {
+       GEOM::GEOM_Object_var aFatherObj = anOp->GetMainShape( it.data() );
+       GEOM::GEOM_Object_var aFindedObject = findObjectInFather(aFatherObj, it.key() );
+      
+       //Add Object to study if its not exist
+       if ( aFindedObject == GEOM::GEOM_Object::_nil() )
+         GeometryGUI::GetGeomGen()->AddInStudy(GeometryGUI::ClientStudyToStudy(aDStudy),
+                                             it.data(), it.key(), aFatherObj );
+      }
+      else {
+       //cout << " anOperations is NULL! " << endl;
+      }
+    }
+}  
+