]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
refs #1334 debug BR_1334_MPROF
authorisn <isn@opencascade.com>
Thu, 9 Nov 2017 14:04:14 +0000 (17:04 +0300)
committerisn <isn@opencascade.com>
Thu, 9 Nov 2017 14:10:40 +0000 (17:10 +0300)
src/HYDROData/HYDROData_Document.cxx
src/HYDROData/HYDROData_Document.h
src/HYDROGUI/HYDROGUI_ProfileDlg.cxx
src/HYDROGUI/HYDROGUI_ProfileDlg.h
src/HYDROGUI/HYDROGUI_ProfileOp.cxx
src/HYDROGUI/resources/HYDROGUI_msg_en.ts

index b59211f6e3cf6e0703b456cdca13852c54645f9b..d8abe576f94f2d92b1b2d87fb8d1bd064b970e53 100644 (file)
@@ -743,6 +743,20 @@ HYDROData_SequenceOfObjects HYDROData_Document::FindObjectsByNames(
   return aResSeq;
 }
 
+HYDROData_SequenceOfObjects HYDROData_Document::CollectAllObjects( const ObjectKind theObjectKind ) const
+{
+  HYDROData_SequenceOfObjects aResSeq;
+  HYDROData_Iterator anIter( this, theObjectKind );
+  for( ; anIter.More(); anIter.Next() )
+  {
+    Handle(HYDROData_Entity) anObject = anIter.Current();
+    if( anObject.IsNull() )
+      continue;
+    aResSeq.Append( anObject );
+  }
+  return aResSeq;
+}
+
 HYDROData_Document::HYDROData_Document()
 {
   HYDROData_Application::GetApplication()->NewDocument("BinOcaf", myDoc);
index 4c0368f81d141b2ff4c450c15d747e02d658c30a..ce3bde519137c3afe750f1b4ce4410409bfa1fb4 100644 (file)
@@ -210,6 +210,10 @@ public:
     const QStringList& theNames, 
     const ObjectKind   theObjectKind = KIND_UNKNOWN ) const;
 
+  //! Collect all data objects with given object type
+  HYDRODATA_EXPORT HYDROData_SequenceOfObjects CollectAllObjects(
+    const ObjectKind theObjectKind = KIND_UNKNOWN ) const;
+
 public:
   
   //! Returns interpolator factory instance
index 04d1d4ec5f785dcd20ed99f605a1b4bb0df519d3..c20841a241f0df0b6fa9f7c0025d592435bbfdde 100644 (file)
@@ -21,6 +21,7 @@
 #include "HYDROGUI_Tool.h"
 #include "HYDROGUI_AISTrihedron.h"
 #ifndef TEST_MODE
+#include <HYDROGUI_Module.h>
 #include "HYDROGUI_Tool2.h"
 #endif
 
@@ -38,7 +39,7 @@
 #ifndef TEST_MODE
 #include <LightApp_Application.h>
 #endif
-
+#include <SUIT_Desktop.h>
 #include <SUIT_Session.h>
 #include <SUIT_ResourceMgr.h>
 
@@ -51,7 +52,7 @@
 #include <QSettings>
 #include <QListWidget>
 #include <QPushButton>
-
+#include <SUIT_MessageBox.h>
 
 const QString splitter_key = "HYDROGUI_ProfileDlg::splitter";
 
@@ -109,7 +110,7 @@ HYDROGUI_ProfileDlg::HYDROGUI_ProfileDlg( HYDROGUI_Module* theModule, const QStr
   connect( myEditorWidget, SIGNAL( subOperationFinished(QWidget*) ), this, SLOT( processFinishedSubOperation(QWidget*) ) );
   if (!mySingleProfileMode)
   {
-    //connect( myProfileNames, SIGNAL( currentTextChanged(QString)), SLOT(ProfileNameChanged(QString)) );
+    connect( myProfileNames, SIGNAL( currentTextChanged(QString)), SLOT(ProfileNameChanged(QString)) );
     connect( myProfileNames, SIGNAL( itemSelectionChanged()), this, SLOT( onProfileIndexChanged()));
     connect( myProfileNames, SIGNAL( itemChanged(QListWidgetItem*)), this, SLOT( onProfileNameChanged(QListWidgetItem*)));
     connect( myAddProfBtn, SIGNAL( clicked(bool)), this, SLOT( onAddBtnPressed(bool)));
@@ -160,6 +161,8 @@ void HYDROGUI_ProfileDlg::setProfileName( const QString& theName )
 void HYDROGUI_ProfileDlg::eraseProfile( int index )
 {
   myProfileNames->takeItem(index);
+  if (myProfileNames->count() == 1)
+    myRemProfBtn->setEnabled(false);
 }
 
 void HYDROGUI_ProfileDlg::addProfileName( const QString& theName, const QColor& theColor )
@@ -178,6 +181,8 @@ void HYDROGUI_ProfileDlg::addProfileName( const QString& theName, const QColor&
   //anItem->setBackground(QBrush(theColor));
   if (count == 1)
     anItem->setSelected(true);
+  if (count > 1)
+    myRemProfBtn->setEnabled(true);
   myProfileNames->blockSignals(false);
 }
 
@@ -256,10 +261,10 @@ void HYDROGUI_ProfileDlg::processFinishedSubOperation( QWidget* theWidget )
   myAddElementBox->hide();
 }
 
-//void HYDROGUI_ProfileDlg::ProfileNameChanged(QString theNewText)
-//{
-//  myProfileNames->setItemText( myProfileNames->currentIndex(), theNewText ); //TODO???
-//}
+void HYDROGUI_ProfileDlg::ProfileNameChanged(QString text)
+{
+  myCurrentName = text;
+}
 
 void HYDROGUI_ProfileDlg::onProfileIndexChanged()
 {
@@ -326,9 +331,29 @@ void HYDROGUI_ProfileDlg::onRemoveBtnPressed(bool)
 void HYDROGUI_ProfileDlg::onProfileNameChanged(QListWidgetItem* item)
 {
   int ind = GetProfileSelectionIndex();
-  //if (ind > -1)
-    //TODO
-  QString text = item->text();
+  if (ind > -1)
+  {
+    int count = myProfileNames->count();
+    QSet<QString> names;
+    for (int i = 0; i < count; i++)
+    {
+      QListWidgetItem* citem = myProfileNames->item(i);
+      if (item!=citem)
+        names << citem->text();
+    }
+    QString curText = item->text();
+    myProfileNames->blockSignals(true);
+    if (names.contains(curText))
+    {
+      QString mes = tr( "PROFILE_ALREADY_EXISTS" );
+      QString title = tr( "PROFILEOP_WARNING" );
+#ifndef TEST_MODE
+      SUIT_MessageBox::warning( module()->getApp()->desktop(), title, mes );
+#endif
+      item->setText(myCurrentName);
+    }
+    myProfileNames->blockSignals(false);
+  }
 }
 
 void HYDROGUI_ProfileDlg::SetSingleProfileMode(bool SingleMode)
index d8705434da91f2ae06a881c6219af9fec3ce6b3a..36ad245df441cbd3e2f71be12ad8099196a19565 100644 (file)
@@ -68,7 +68,7 @@ public:
 protected slots:
   void processStartedSubOperation( QWidget*, bool );
   void processFinishedSubOperation( QWidget* );
-  //void ProfileNameChanged(QString);
+  void ProfileNameChanged(QString);
   void onProfileIndexChanged();
   void onAddBtnPressed(bool);
   void onRemoveBtnPressed(bool);
@@ -97,6 +97,7 @@ public://temp TODO
   QGroupBox*             myAddElementBox;
   std::vector<HYDROGUI_CurveCreatorProfile*>* myProfilesPointer;
   bool                   mySingleProfileMode;
+  QString                myCurrentName;
 };
 
 #endif
index 7bbae5ff3653ad203458c43ef13c65282e116712..db19ae679766d769a881fea9fd19027852627744 100644 (file)
@@ -38,7 +38,8 @@
 #include <OCCViewer_ViewManager.h>
 #include <OCCViewer_ViewModel.h>
 #include <OCCViewer_ViewWindow.h>
-
+#include <SUIT_MessageBox.h>
+#include <SUIT_Desktop.h>
 #include <OCCViewer_AISSelector.h>
 
 #include <Precision.hxx>
@@ -339,7 +340,7 @@ HYDROGUI_InputPanel* HYDROGUI_ProfileOp::createInputPanel() const
     SLOT( onRemoveProfile(int) ) );  
   return aDlg;
 }
-
+#include <set>
 bool HYDROGUI_ProfileOp::processApply( int& theUpdateFlags,
                                        QString& theErrorMsg,
                                        QStringList& theBrowseObjectsEntries )
@@ -351,23 +352,32 @@ bool HYDROGUI_ProfileOp::processApply( int& theUpdateFlags,
   QStringList aProfileNames = aPanel->getProfileNames();
   QVector<QString> aProfileNamesFiltered;
   int i = 0;
+ // QSet<QString> edObjStrMap = aProfileNames.toSet();
+  QSet<QString> ObjStrMapNE ;
+  HYDROData_SequenceOfObjects allobj = doc()->CollectAllObjects();
+  for (int i=1;i<=allobj.Size();i++ )
+    ObjStrMapNE.insert(allobj(i)->GetName());
+  for (int i=1; i<=myEditedObjects.Size();i++)
+    ObjStrMapNE.remove(myEditedObjects(i)->GetName());
+  bool warn = false;
+  QString title = tr( "PROFILEOP_WARNING" );
+  QString mes = tr("PROFILE_RENAMING_NOTIF") + "\n";
   foreach (QString profName, aProfileNames)
   {
     i++;
-    if ( profName.isEmpty() )
-    {
-      theErrorMsg = tr( "INCORRECT_OBJECT_NAME" ); //?
-      continue;
-    }
-    Handle(HYDROData_Entity) anObject = HYDROGUI_Tool::FindObjectByName( module(), profName );
-    if( !myIsEdit || (!anObject.IsNull() && myEditedObjects(i)->GetName() != anObject->GetName() ) )
+    if( !myIsEdit || ObjStrMapNE.contains(profName) || profName.isEmpty() )
     {
-      profName = HYDROData_Tool::GenerateObjectName(doc(), "Profile");
-      //theErrorMsg = tr( "OBJECT_EXISTS_IN_DOCUMENT" ).arg( profName );
-      continue;
+      QString newName = HYDROData_Tool::GenerateObjectName(doc(), "Profile");
+      mes += profName + " => " + newName + "\n";
+      profName = newName;
+      warn = true;
     }
     aProfileNamesFiltered.append(profName);
   }
+  if (warn)
+#ifndef TEST_MODE
+    SUIT_MessageBox::warning( module()->getApp()->desktop(), title, mes );
+#endif
   //  
   theUpdateFlags = UF_Model;
   if (myIsEdit)
@@ -406,23 +416,7 @@ bool HYDROGUI_ProfileOp::processApply( int& theUpdateFlags,
   return true;
 }
 
-/*void HYDROGUI_ProfileOp::displayPreview()
-{
- /* HYDROGUI_ProfileDlg* aPanel = dynamic_cast<HYDROGUI_ProfileDlg*>( inputPanel() );
-  if( aPanel )
-  {
-    Handle(AIS_InteractiveContext) aCtx = aPanel->getAISContext();
-    if( !aCtx.IsNull() )
-    {
-      CurveCreator_Displayer* aDisplayer = new CurveCreator_Displayer( aCtx );
-      myProfile->setDisplayer( aDisplayer );
-      aDisplayer->display( myProfile->getAISObject( true ), true );
-    }
-  }
-}*/
-
-void HYDROGUI_ProfileOp::displayPreviews(
-  const QMap<HYDROGUI_CurveCreatorProfile*, QColor>& CurveToColor,
+void HYDROGUI_ProfileOp::displayPreviews(const QMap<HYDROGUI_CurveCreatorProfile*, QColor>& CurveToColor,
   int firstIndProf, int lastIndProf, bool createNewDisplayer, bool SwitchToFirstProf)
 {
   HYDROGUI_ProfileDlg* aPanel = dynamic_cast<HYDROGUI_ProfileDlg*>( inputPanel() );
@@ -452,7 +446,7 @@ void HYDROGUI_ProfileOp::displayPreviews(
         myDisplayer->display( CC->getAISObject( true ), true );
       }
     }
-    if (SwitchToFirstProf && !myProfiles.empty())
+    if (SwitchToFirstProf && myProfiles.size() > 1)
       aPanel->switchToFirstProfile();
   }
 }
index a6b85eb24fb25da3e9ee049d55c840290c8f9006..d44e0f0f07bd1dc1f716ed4f1126aafca3539b47 100644 (file)
@@ -2006,8 +2006,15 @@ Would you like to remove all references from the image?</translation>
       <source>NUMBER_OF_PROFILE_POINTS_INCORRECT</source>
       <translation>Number of profile points should not be less than 3.</translation>
     </message>
+    <message>
+      <source>PROFILEOP_WARNING</source>
+      <translation>Warning</translation>
+    </message>
+    <message>
+      <source>PROFILE_RENAMING_NOTIF</source>
+      <translation>The next profile(s) have been renamed:</translation>
+    </message>
   </context>
-
   <context>
     <name>HYDROGUI_RemoveImageRefsOp</name>
     <message>
@@ -2122,6 +2129,23 @@ Would you like to remove all references from the image?</translation>
       <source>Z_TITLE</source>
       <translation>Z</translation>
     </message>
+    <message>
+      <source>ADD_PROFILE</source>
+      <translation>Add Profile(s)</translation>
+    </message>
+    <message>
+      <source>REMOVE_PROFILE</source>
+      <translation>Remove Profile</translation>
+    </message>
+    <message>
+      <source>PROFILE_ALREADY_EXISTS</source>
+      <translation>Profile with this name is already exists</translation>
+    </message>
+    <message>
+      <source>PROFILEDLG_WARNING</source>
+      <translation>Warning</translation>
+    </message>
+
   </context>
 
   <context>