Salome HOME
Add tests for connection with SHAPERSTUDY
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_Selection.cxx
index fbc43c922d46b397ad32b2e0236898043b67c281..ab4a1ca8ec4d3d1f80aab645f8770fd9e97e2493 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2016  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2019  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
@@ -43,6 +43,8 @@
 #include <SalomeApp_Application.h>
 #include <LightApp_VTKSelector.h>
 #include <SVTK_ViewWindow.h>
+#include <LightApp_SelectionMgr.h>
+#include <LightApp_DataOwner.h>
 
 // IDL includes
 #include <SALOMEconfig.h>
@@ -77,6 +79,8 @@ void SMESHGUI_Selection::init( const QString& client, LightApp_SelectionMgr* mgr
 
   if( mgr )
   {
+    myOwners.clear();
+    mgr->selected(myOwners, client);
     for( int i=0, n=count(); i<n; i++ ) {
       myTypes.append( typeName( type( entry( i ) ) ) );
       myControls.append( controlMode( i ) );
@@ -140,6 +144,7 @@ QVariant SMESHGUI_Selection::parameter( const int ind, const QString& p ) const
   else if ( p=="nbChildren")            val = QVariant( nbChildren( ind ) );
   else if ( p=="isContainer")           val = QVariant( isContainer( ind ) );
   else if ( p=="guiState")              val = QVariant( guiState() );
+  else if ( p=="canBreakLink")          val = QVariant( canBreakLink(ind) );
 
   if ( val.isValid() )
     return val;
@@ -605,6 +610,33 @@ bool SMESHGUI_Selection::hasGeomReference( int ind ) const
   return false;
 }
 
+//=======================================================================
+//function : canBreakLink
+//purpose  : returns true if selected object is a Shaper object and it can break link
+//=======================================================================
+
+bool SMESHGUI_Selection::canBreakLink( int ind ) const
+{
+  if ( ind >= 0 && ind < myTypes.count()) {
+    if (isReference(ind)) {
+      SUIT_DataOwner* aOwn = myOwners.at(ind);
+      LightApp_DataOwner* sowner = dynamic_cast<LightApp_DataOwner*>(aOwn);
+      QString aEntry = sowner->entry();
+      _PTR(SObject) aSObject = SMESH::getStudy()->FindObjectID(aEntry.toStdString());
+      _PTR(SObject) aFatherObj = aSObject->GetFather();
+      _PTR(SComponent) aComponent = aFatherObj->GetFatherComponent();
+      if (aComponent->ComponentDataType() == "SMESH") {
+        QString aObjEntry = entry(ind);
+        _PTR(SObject) aGeomSObject = SMESH::getStudy()->FindObjectID(aObjEntry.toStdString());
+        GEOM::GEOM_Object_var aObject = SMESH::SObjectToInterface<GEOM::GEOM_Object>(aGeomSObject);
+        if (!aObject->_is_nil())
+          return aObject->IsParametrical();
+      }
+    }
+  }
+  return false;
+}
+
 //=======================================================================
 //function : isEditableHyp
 //purpose  :