Salome HOME
lot 10 - warnings for DTM - untested
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_ProfileOp.cxx
index db19ae679766d769a881fea9fd19027852627744..0ad3e45ac4789506905d246b01f21e111f815952 100644 (file)
@@ -30,6 +30,7 @@
 #include <CurveCreator_Displayer.hxx>
 #include <HYDROData_Entity.h>
 #include <QSet>
+#include <set>
 
 #include <LightApp_Application.h>
 #include <LightApp_SelectionMgr.h>
@@ -128,7 +129,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" ) );
 }
@@ -183,7 +184,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();
@@ -192,7 +193,7 @@ void HYDROGUI_ProfileOp::startOperation()
   setPreviewManager( aPanel->viewManager() );
   setCursor();
 
-  aPanel->SetSingleProfileMode(mySingleProfileMode); 
+  //aPanel->SetSingleProfileMode(mySingleProfileMode); 
   QMap<HYDROGUI_CurveCreatorProfile*, QColor> CurveToColor;
   if( lenP )
   {
@@ -214,7 +215,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
@@ -223,11 +224,12 @@ void HYDROGUI_ProfileOp::startOperation()
     {
       HYDROGUI_CurveCreatorProfile* CC = myProfiles[i];
       const Handle(HYDROData_Profile)& CP = myCurveToProfile.Find(CC);
-      const QColor& CurCol = PColors[i]; 
+      QColor CurCol = PColors[i]; 
+      CP->GetProfileColor(CurCol);
       CurveToColor[CC] = CurCol;
       const QString& profName = CP->GetName();
       const QColor& PColor = CurCol;
-      if (!mySingleProfileMode)
+      if (myIsEdit)
         aPanel->addProfileName(profName, PColor);
       else
         aPanel->setProfileName(profName);
@@ -261,7 +263,7 @@ void HYDROGUI_ProfileOp::onAddProfiles()
   int ExistingProfLen = myEditedObjects.Length();
   for (int i = 1; i <= aSelectedObj.Length(); i++)
   {
-    Handle(HYDROData_Entity) CurProf = Handle(HYDROData_Entity)::DownCast(aSelectedObj(i));
+    Handle(HYDROData_Profile) CurProf = Handle(HYDROData_Profile)::DownCast(aSelectedObj.Value(i));
     if (CurProf.IsNull())
       continue;
     if (!edObjNamesMap.contains(CurProf->GetName()))
@@ -269,18 +271,30 @@ 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++)
     {
       Handle(HYDROData_Profile) aCProfile = Handle(HYDROData_Profile)::DownCast(myEditedObjects(i)); 
+
       QString aProfileName;
       if( !aCProfile.IsNull() )
       {
@@ -302,11 +316,12 @@ void HYDROGUI_ProfileOp::onAddProfiles()
     {
       HYDROGUI_CurveCreatorProfile* CC = myProfiles[i];
       const Handle(HYDROData_Profile)& CP = myCurveToProfile.Find(CC);
-      const QColor& CurCol = PColors[i-ExistingProfLen]; 
+      QColor CurCol = PColors[i-ExistingProfLen]; 
+      CP->GetProfileColor(CurCol);
       CurveToColor[CC] = CurCol;
       const QString& profName = CP->GetName();
       const QColor& PColor = CurCol;
-      if (!mySingleProfileMode)
+      if (myIsEdit)
         aPanel->addProfileName(profName, PColor);
       else
         aPanel->setProfileName(profName);
@@ -333,14 +348,15 @@ 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 )
@@ -374,7 +390,7 @@ bool HYDROGUI_ProfileOp::processApply( int& theUpdateFlags,
     }
     aProfileNamesFiltered.append(profName);
   }
-  if (warn)
+  if (myIsEdit && warn)
 #ifndef TEST_MODE
     SUIT_MessageBox::warning( module()->getApp()->desktop(), title, mes );
 #endif
@@ -386,6 +402,7 @@ bool HYDROGUI_ProfileOp::processApply( int& theUpdateFlags,
     {
       Handle(HYDROData_Profile) HProf = Handle(HYDROData_Profile)::DownCast(myEditedObjects(i));
       int stat = CurveCrProfileToHProfile(myProfiles[i-1], HProf, aProfileNamesFiltered[i-1], true);
+      HProf->SetProfileColor(HYDROData_Tool::toQtColor(myProfiles[i-1]->getColorSection(0)));
       if (stat == 0)
         continue;
       else if (stat == -1)
@@ -401,6 +418,7 @@ bool HYDROGUI_ProfileOp::processApply( int& theUpdateFlags,
   {
     Handle(HYDROData_Profile) aNewProfileObj = Handle(HYDROData_Profile)::DownCast( doc()->CreateObject( KIND_PROFILE ) ); 
     int stat = CurveCrProfileToHProfile(myProfiles[0], aNewProfileObj, aProfileNamesFiltered[0], false);
+    aNewProfileObj->SetProfileColor(HYDROData_Tool::toQtColor(myProfiles[0]->getColorSection(0)));
     if (stat == 0)
       return false;
     else if (stat == -1)
@@ -441,7 +459,7 @@ void HYDROGUI_ProfileOp::displayPreviews(const QMap<HYDROGUI_CurveCreatorProfile
         Quantity_Color CurOCCCol = HYDROData_Tool::toOccColor(QCurCol);
         CC->setDisplayer( myDisplayer );
         CC->myPointAspectColor = CurOCCCol;
-        CC->myCurveColor = CurOCCCol;
+        CC->setColorSectionInternal(0, CurOCCCol);
         CC->myLineWidth = 1;
         myDisplayer->display( CC->getAISObject( true ), true );
       }