Salome HOME
NPAL 18378
[modules/geom.git] / src / GEOMBase / GEOMBase_Helper.cxx
index 9d65029f86cd859c4f16c12c31f118f0b31d7d47..95ff8f0ec06fca07cac5848950a7bc97519ce146 100755 (executable)
@@ -17,7 +17,7 @@
 //  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.org
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
 //
 //
@@ -44,9 +44,9 @@
 #include <SalomeApp_Application.h>
 #include <SalomeApp_Study.h>
 #include <LightApp_SelectionMgr.h>
+#include <LightApp_DataOwner.h>
 #include <SalomeApp_Tools.h>
 #include <SalomeApp_DataModel.h>
-#include <SalomeApp_Module.h>
 
 #include <OCCViewer_ViewModel.h>
 #include <SVTK_ViewModel.h>
@@ -106,9 +106,13 @@ GEOMBase_Helper::~GEOMBase_Helper()
     erasePreview();
   if ( hasCommand() )
     abortCommand();
-
-  globalSelection( GEOM_ALLOBJECTS, true );
-
+  SalomeApp_Application* app = (SalomeApp_Application*)(SUIT_Session::session()->activeApplication());
+  if (app) {
+    GeometryGUI* aGeomGUI = dynamic_cast<GeometryGUI*>( app->module( "Geometry" ) );
+    if(aGeomGUI)
+      globalSelection(aGeomGUI->getLocalSelectionMode() , true );
+  }
+  
   if (myDisplayer)
     delete myDisplayer;
 }
@@ -244,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;
@@ -266,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 );
       }
@@ -290,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 );
@@ -313,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 );
@@ -757,8 +770,8 @@ bool GEOMBase_Helper::onAccept( const bool publish, const bool useTransaction )
        showError();
       }
       else {
+       addSubshapesToStudy(); // add Subshapes if local selection
        const int nbObjs = objects.size();
-       bool withChildren = false;
         int aNumber = 1;
        for ( ObjectList::iterator it = objects.begin(); it != objects.end(); ++it ) {
          if ( publish ) {
@@ -779,14 +792,15 @@ bool GEOMBase_Helper::onAccept( const bool publish, const bool useTransaction )
                aName = GEOMBase::GetDefaultName( getPrefix( *it ) );
            }
            addInStudy( *it, aName.latin1() );
-           withChildren = false;
+            // updateView=false
            display( *it, false );
          }
-         else { // asv : fix of PAL6454. If publish==false, then the original shape was modified, and need to be re-cached in GEOM_Client
-                // before redisplay
+         else {
+            // asv : fix of PAL6454. If publish==false, then the original shape
+            // was modified, and need to be re-cached in GEOM_Client before redisplay
            clearShapeBuffer( *it );
-           withChildren = true;
-           redisplay( *it, withChildren, false );
+            // withChildren=true, updateView=false
+           redisplay( *it, true, false );
           }
        }
 
@@ -905,22 +919,23 @@ QString GEOMBase_Helper::getPrefix( GEOM::GEOM_Object_ptr theObj ) const
   if ( !myPrefix.isEmpty() || theObj->_is_nil() )
     return myPrefix;
 
-  TopoDS_Shape aShape;
-  if ( !GEOMBase::GetShape( theObj, aShape ) )
-    return "";
-
-  long aType = aShape.ShapeType();
+  //TopoDS_Shape aShape;
+  //if ( !GEOMBase::GetShape( theObj, aShape ) )
+  //  return "";
+  //
+  //long aType = aShape.ShapeType();
+  GEOM::shape_type aType = theObj->GetShapeType();
 
   switch ( aType )
   {
-    case TopAbs_VERTEX   : return QObject::tr( "GEOM_VERTEX" );
-    case TopAbs_EDGE     : return QObject::tr( "GEOM_EDGE" );
-    case TopAbs_WIRE     : return QObject::tr( "GEOM_WIRE" );
-    case TopAbs_FACE     : return QObject::tr( "GEOM_FACE" );
-    case TopAbs_SHELL    : return QObject::tr( "GEOM_SHELL" );
-    case TopAbs_SOLID    : return QObject::tr( "GEOM_SOLID" );
-    case TopAbs_COMPSOLID: return QObject::tr( "GEOM_COMPOUNDSOLID" );
-    case TopAbs_COMPOUND : return QObject::tr( "GEOM_COMPOUND" );
+    case GEOM::VERTEX   : return QObject::tr( "GEOM_VERTEX" );
+    case GEOM::EDGE     : return QObject::tr( "GEOM_EDGE" );
+    case GEOM::WIRE     : return QObject::tr( "GEOM_WIRE" );
+    case GEOM::FACE     : return QObject::tr( "GEOM_FACE" );
+    case GEOM::SHELL    : return QObject::tr( "GEOM_SHELL" );
+    case GEOM::SOLID    : return QObject::tr( "GEOM_SOLID" );
+    case GEOM::COMPSOLID: return QObject::tr( "GEOM_COMPOUNDSOLID" );
+    case GEOM::COMPOUND : return QObject::tr( "GEOM_COMPOUND" );
     default : return "";
   }
 }
@@ -981,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;
+      }
+    }
+}  
+