Salome HOME
Enable simultaneous usage of several StdMeshersGUI_SubShapeSelectorWdg's
authoreap <eap@opencascade.com>
Fri, 7 Aug 2020 09:14:55 +0000 (12:14 +0300)
committereap <eap@opencascade.com>
Fri, 7 Aug 2020 09:14:55 +0000 (12:14 +0300)
Add SMESH_Gen_i::CountInPyDump(text) which is useful for defining uniquely
named variables in dump python scripts

src/SMESH_I/SMESH_Gen_i.hxx
src/SMESH_I/SMESH_PythonDump.cxx
src/StdMeshersGUI/StdMeshersGUI_SubShapeSelectorWdg.cxx
src/StdMeshersGUI/StdMeshersGUI_SubShapeSelectorWdg.h

index 895f745fcac93c3f3b572602a4c81a85b8676a21..d6cb5b130647cc5b9a84acfd0fc200f398520757 100644 (file)
@@ -494,6 +494,8 @@ public:
 
   void CleanPythonTrace();
 
 
   void CleanPythonTrace();
 
+  static int CountInPyDump(const TCollection_AsciiString& text);
+
   // *****************************************
   // Internal methods
   // *****************************************
   // *****************************************
   // Internal methods
   // *****************************************
index 04a0fc9a88c98000cfb7f422bbc9150e1ade3761..e1c3002c0a583800cfd546adf15618eb0b3c12ba 100644 (file)
@@ -40,6 +40,8 @@
 #include <TColStd_HSequenceOfInteger.hxx>
 #include <TCollection_AsciiString.hxx>
 
 #include <TColStd_HSequenceOfInteger.hxx>
 #include <TCollection_AsciiString.hxx>
 
+#include <cstring>
+
 #ifdef _DEBUG_
 static int MYDEBUG = 0;
 #else
 #ifdef _DEBUG_
 static int MYDEBUG = 0;
 #else
@@ -77,7 +79,7 @@ namespace SMESH
       TCollection_AsciiString aCollection(Standard_CString(aString.c_str()));
       if(!aCollection.IsEmpty())
       {
       TCollection_AsciiString aCollection(Standard_CString(aString.c_str()));
       if(!aCollection.IsEmpty())
       {
-        const std::string & objEntry = SMESH_Gen_i::GetSMESHGen()->GetLastObjEntry();
+        const std::string & objEntry = aSMESHGen->GetLastObjEntry();
         if ( !objEntry.empty() )
           aCollection += (TVar::ObjPrefix() + objEntry ).c_str();
         aSMESHGen->AddToPythonScript(aCollection);
         if ( !objEntry.empty() )
           aCollection += (TVar::ObjPrefix() + objEntry ).c_str();
         aSMESHGen->AddToPythonScript(aCollection);
@@ -1388,3 +1390,55 @@ void SMESH_Gen_i::CleanPythonTrace()
     myPythonScript->Clear();
   }
 }
     myPythonScript->Clear();
   }
 }
+
+//================================================================================
+/*!
+ * \brief Count inclusions of a string in a raw Python dump script
+ */
+//================================================================================
+
+int SMESH_Gen_i::CountInPyDump(const TCollection_AsciiString& theText)
+{
+  int count = 0;
+
+  SALOMEDS::Study_var aStudy = getStudyServant();
+  if ( CORBA::is_nil( aStudy ))
+    return count;
+
+  SMESH_Gen_i* me = GetSMESHGen();
+  CORBA::String_var compDataType = me->ComponentDataType();
+  SALOMEDS::SObject_wrap aSO = aStudy->FindComponent( compDataType.in() );
+  if ( CORBA::is_nil( aSO ))
+    return count;
+
+  // Trace saved in the study
+  SALOMEDS::GenericAttribute_wrap attr;
+  if ( aSO->FindAttribute( attr.inout(), "AttributePythonObject" ))
+  {
+    SALOMEDS::AttributePythonObject_var pyAttr =
+      SALOMEDS::AttributePythonObject::_narrow( attr );
+    CORBA::String_var script = pyAttr->GetObject();
+    for ( const char * scriptPos = script.in(); true; ++scriptPos )
+      if (( scriptPos = strstr( scriptPos, theText.ToCString() )))
+        ++count;
+      else
+        break;
+  }
+
+  // New python commands
+  if ( !me->myPythonScript.IsNull() )
+  {
+    const int nbLines = me->myPythonScript->Length();
+    for ( int i = 1; i <= nbLines; ++i )
+    {
+      const TCollection_AsciiString& line = me->myPythonScript->Value( i );
+      for ( int loc = 1; loc <= line.Length(); ++loc )
+        if (( loc = line.Location( theText, loc, line.Length() )))
+          ++count;
+        else
+          break;
+    }
+  }
+
+  return count;
+}
index 54560d8fc9bf96b6a7bc3b9ec70dda0a99dbeff7..31db0a7be7f4e5add339605081fde9fe0cf9eb0a 100644 (file)
@@ -74,7 +74,8 @@ StdMeshersGUI_SubShapeSelectorWdg
 ::StdMeshersGUI_SubShapeSelectorWdg( QWidget *        parent,
                                      TopAbs_ShapeEnum subShType,
                                      const bool       toShowList,
 ::StdMeshersGUI_SubShapeSelectorWdg( QWidget *        parent,
                                      TopAbs_ShapeEnum subShType,
                                      const bool       toShowList,
-                                     const bool       toShowActivateBtn ):
+                                     const bool       toShowActivateBtn,
+                                     const int        minListWidth ):
   QWidget( parent ),
   myMaxSize( -1 ),
   myPreviewActor( 0 )
   QWidget( parent ),
   myMaxSize( -1 ),
   myPreviewActor( 0 )
@@ -93,8 +94,8 @@ StdMeshersGUI_SubShapeSelectorWdg
     myAddButton      = new QPushButton( tr( "SMESH_BUT_ADD" ),    this );
     myRemoveButton   = new QPushButton( tr( "SMESH_BUT_REMOVE" ), this );
     myListWidget->setSelectionMode( QListWidget::ExtendedSelection );
     myAddButton      = new QPushButton( tr( "SMESH_BUT_ADD" ),    this );
     myRemoveButton   = new QPushButton( tr( "SMESH_BUT_REMOVE" ), this );
     myListWidget->setSelectionMode( QListWidget::ExtendedSelection );
-    myListWidget->setMinimumWidth(300);
-    myListWidget->setWrapping(true);
+    myListWidget->setMinimumWidth( minListWidth );
+    myListWidget->setWrapping( true );
     myActivateButton->setCheckable( true );
   }
   else
     myActivateButton->setCheckable( true );
   }
   else
@@ -254,6 +255,20 @@ void StdMeshersGUI_SubShapeSelectorWdg::ShowPreview( bool visible)
   }
 }
 
   }
 }
 
+//================================================================================
+/*!
+ * \brief Connect selection slots
+  * \param other - another StdMeshersGUI_ObjectReferenceParamWdg
+ */
+//================================================================================
+
+void StdMeshersGUI_SubShapeSelectorWdg::
+AvoidSimultaneousSelection ( StdMeshersGUI_SubShapeSelectorWdg* other)
+{
+  connect(other, SIGNAL(selectionActivated()), this, SLOT(deactivateSelection()));
+  connect(this, SIGNAL(selectionActivated()), other, SLOT(deactivateSelection()));
+}
+
 //================================================================================
 /*!
  * \brief Connect/disconnect to change of selection
 //================================================================================
 /*!
  * \brief Connect/disconnect to change of selection
@@ -275,7 +290,7 @@ void StdMeshersGUI_SubShapeSelectorWdg::ActivateSelection( bool toActivate )
 
   if ( toActivate )
   {
 
   if ( toActivate )
   {
-    connect( mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(selectionIntoArgument()));
+    connect( mySelectionMgr, SIGNAL(currentSelectionChanged()), SLOT(selectionIntoArgument()));
   }
   else
   {
   }
   else
   {
@@ -284,6 +299,9 @@ void StdMeshersGUI_SubShapeSelectorWdg::ActivateSelection( bool toActivate )
 
   if ( sender() == myActivateButton )
     ShowPreview( toActivate );
 
   if ( sender() == myActivateButton )
     ShowPreview( toActivate );
+
+  if ( toActivate )
+    emit selectionActivated();
 }
 
 //================================================================================
 }
 
 //================================================================================
index 3f3d3bf1242d4c18b46f9f9dd45067d11a753dd5..9c4f14b359d40eb4714b4d6fe99c1b6d1a3e07b5 100644 (file)
@@ -53,7 +53,8 @@ public:
   StdMeshersGUI_SubShapeSelectorWdg( QWidget*         parent = 0,
                                      TopAbs_ShapeEnum subShType = TopAbs_EDGE,
                                      const bool       toShowList = true,
   StdMeshersGUI_SubShapeSelectorWdg( QWidget*         parent = 0,
                                      TopAbs_ShapeEnum subShType = TopAbs_EDGE,
                                      const bool       toShowList = true,
-                                     const bool       toShowSelectBtn = false);
+                                     const bool       toShowSelectBtn = false,
+                                     const int        minListWidth=300);
   ~StdMeshersGUI_SubShapeSelectorWdg();
 
   SMESH::long_array_var          GetListOfIDs();
   ~StdMeshersGUI_SubShapeSelectorWdg();
 
   SMESH::long_array_var          GetListOfIDs();
@@ -82,12 +83,23 @@ public:
   SMESH_PreviewActorsCollection* GetActorCollection() { return myPreviewActor; }
   void                           ClearSelected();
 
   SMESH_PreviewActorsCollection* GetActorCollection() { return myPreviewActor; }
   void                           ClearSelected();
 
+  void AvoidSimultaneousSelection( StdMeshersGUI_SubShapeSelectorWdg* other);
+
 public slots:
 public slots:
+
   void                           ActivateSelection( bool );
   void                           ActivateSelection( bool );
+  void                           deactivateSelection() { ActivateSelection( false ); }
 
 signals:
   void                           selectionChanged(); // in the list
   void                           shapeSelected();    // globally
 
 signals:
   void                           selectionChanged(); // in the list
   void                           shapeSelected();    // globally
+  /*!
+   * \brief Emitted when selection is activated
+    *
+    * Useful to deactivate one Object Reference param widget when an other
+    * one is activated
+   */
+  void                           selectionActivated();
 
 private:
   void                           updateState();
 
 private:
   void                           updateState();