Salome HOME
refs #1508
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_ProfileOp.cxx
index 7bbae5ff3653ad203458c43ef13c65282e116712..a7ae37ffb0e6844fe49b7f21c24e654074d6784c 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>
@@ -127,7 +128,7 @@ static int CurveCrProfileToHProfile(const HYDROGUI_CurveCreatorProfile* outProfi
 
 HYDROGUI_ProfileOp::HYDROGUI_ProfileOp( HYDROGUI_Module* theModule, bool theIsEdit )
 : HYDROGUI_Operation( theModule ), myIsEdit(theIsEdit), 
-   myDisplayer (NULL), mySingleProfileMode (false)
+   myDisplayer (NULL)
 {
   setName( theIsEdit ? tr( "EDIT_PROFILE" ) : tr( "CREATE_PROFILE" ) );
 }
@@ -182,7 +183,7 @@ void HYDROGUI_ProfileOp::startOperation()
   for (int i = 0; i < myProfiles.size(); i++)
     myProfiles[i] = new HYDROGUI_CurveCreatorProfile();
 
-  mySingleProfileMode = myEditedObjects.IsEmpty() || lenP == 1;  
+  //mySingleProfileMode = myEditedObjects.IsEmpty();  
   HYDROGUI_Operation::startOperation();
 
   HYDROGUI_ProfileDlg* aPanel = (HYDROGUI_ProfileDlg*)inputPanel();
@@ -191,7 +192,7 @@ void HYDROGUI_ProfileOp::startOperation()
   setPreviewManager( aPanel->viewManager() );
   setCursor();
 
-  aPanel->SetSingleProfileMode(mySingleProfileMode); 
+  //aPanel->SetSingleProfileMode(mySingleProfileMode); 
   QMap<HYDROGUI_CurveCreatorProfile*, QColor> CurveToColor;
   if( lenP )
   {
@@ -213,7 +214,7 @@ void HYDROGUI_ProfileOp::startOperation()
     }
     int ext = myCurveToProfile.Extent(); //ext should be equal to lenP
     QVector<QColor> PColors;
-    if (!mySingleProfileMode)
+    if (myIsEdit)
       HYDROData_Tool::GenerateRepeatableRandColors(ext, PColors);
     else
       PColors << QColor(0,0,255); //default color
@@ -226,7 +227,7 @@ void HYDROGUI_ProfileOp::startOperation()
       CurveToColor[CC] = CurCol;
       const QString& profName = CP->GetName();
       const QColor& PColor = CurCol;
-      if (!mySingleProfileMode)
+      if (myIsEdit)
         aPanel->addProfileName(profName, PColor);
       else
         aPanel->setProfileName(profName);
@@ -268,13 +269,24 @@ void HYDROGUI_ProfileOp::onAddProfiles()
   }
 
   int NewLen = myEditedObjects.Length();
+  bool IsNewPoly = NewLen - ExistingProfLen;
+  if (aSelectedObj.IsEmpty())
+  {
+    SUIT_MessageBox::warning( module()->getApp()->desktop(), tr( "PROFILEOP_WARNING" ), tr ("PROFILES_ARE_NOT_SELECTED") );
+    return;
+  }
+  if (!IsNewPoly)
+  {
+    SUIT_MessageBox::warning( module()->getApp()->desktop(), tr( "PROFILEOP_WARNING" ), tr ("PROFILES_ALREADY_PRESENT") );
+    return;
+  }
   myProfiles.resize(myEditedObjects.Length());
   for (int i = myProfiles.size() - 1; i < myEditedObjects.Length(); i++)
     myProfiles[i] = new HYDROGUI_CurveCreatorProfile();
     
   HYDROGUI_ProfileDlg* aPanel = (HYDROGUI_ProfileDlg*)inputPanel();  
   QMap<HYDROGUI_CurveCreatorProfile*, QColor> CurveToColor;
-  if( NewLen - ExistingProfLen )
+  if( IsNewPoly )
   {
     //TODO move to ext func!
     for (int i = ExistingProfLen + 1; i <= NewLen; i++)
@@ -305,7 +317,7 @@ void HYDROGUI_ProfileOp::onAddProfiles()
       CurveToColor[CC] = CurCol;
       const QString& profName = CP->GetName();
       const QColor& PColor = CurCol;
-      if (!mySingleProfileMode)
+      if (myIsEdit)
         aPanel->addProfileName(profName, PColor);
       else
         aPanel->setProfileName(profName);
@@ -332,14 +344,14 @@ void HYDROGUI_ProfileOp::commitOperation()
 
 HYDROGUI_InputPanel* HYDROGUI_ProfileOp::createInputPanel() const
 {
-  HYDROGUI_ProfileDlg* aDlg = new HYDROGUI_ProfileDlg( module(), getName(), mySingleProfileMode );
+  HYDROGUI_ProfileDlg* aDlg = new HYDROGUI_ProfileDlg( module(), getName(), myIsEdit );
   connect( aDlg, SIGNAL( AddProfiles() ), this, 
     SLOT( onAddProfiles() ) );
   connect( aDlg, SIGNAL( RemoveProfile(int) ), this, 
     SLOT( onRemoveProfile(int) ) );  
   return aDlg;
 }
-
+#include <set>
 bool HYDROGUI_ProfileOp::processApply( int& theUpdateFlags,
                                        QString& theErrorMsg,
                                        QStringList& theBrowseObjectsEntries )
@@ -351,23 +363,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() )
+    if( !myIsEdit || ObjStrMapNE.contains(profName) || 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() ) )
-    {
-      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 (myIsEdit && warn)
+#ifndef TEST_MODE
+    SUIT_MessageBox::warning( module()->getApp()->desktop(), title, mes );
+#endif
   //  
   theUpdateFlags = UF_Model;
   if (myIsEdit)
@@ -406,23 +427,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 +457,7 @@ void HYDROGUI_ProfileOp::displayPreviews(
         myDisplayer->display( CC->getAISObject( true ), true );
       }
     }
-    if (SwitchToFirstProf && !myProfiles.empty())
+    if (SwitchToFirstProf && myProfiles.size() > 1)
       aPanel->switchToFirstProfile();
   }
 }