]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
refs #1334 (draft, non-compiled)
authorisn <isn@opencascade.com>
Mon, 23 Oct 2017 16:21:34 +0000 (19:21 +0300)
committerisn <isn@opencascade.com>
Wed, 8 Nov 2017 18:44:36 +0000 (21:44 +0300)
src/HYDROData/HYDROData_Tool.cxx
src/HYDROData/HYDROData_Tool.h
src/HYDROGUI/HYDROGUI_CalculationOp.cxx
src/HYDROGUI/HYDROGUI_CalculationOp.h
src/HYDROGUI/HYDROGUI_CurveCreatorProfile.cxx
src/HYDROGUI/HYDROGUI_Module.cxx
src/HYDROGUI/HYDROGUI_ProfileDlg.cxx
src/HYDROGUI/HYDROGUI_ProfileDlg.h
src/HYDROGUI/HYDROGUI_ProfileOp.cxx
src/HYDROGUI/HYDROGUI_ProfileOp.h
src/HYDRO_tests/test_HYDROGUI_ProfilesDlg.cxx

index 812bccb6b8ed006f2ee6e5335d57fa1a3339a3b5..e3a96059352a8e6ff88b078351cac7783edb9b42 100644 (file)
@@ -27,6 +27,7 @@
 #include <QFile>
 #include <QStringList>
 #include <QTextStream>
+#include <QSet>
 #include <BRep_Tool.hxx>
 #include <BRepAdaptor_Surface.hxx>
 #include <BRepTopAdaptor_FClass2d.hxx>
@@ -55,6 +56,7 @@
 #include <TopTools_ListIteratorOfListOfShape.hxx>
 
 static int aMaxNameId = INT_MAX;
+static int aMaxColorNb = 92000;
 void HYDROData_Tool::WriteStringsToFile( QFile&             theFile,
                                          const QStringList& theStrings,
                                          const QString&     theSep )
@@ -316,6 +318,50 @@ QColor HYDROData_Tool::toQtColor( const Quantity_Color& theColor )
   return QColor( r, g, b );
 }
 
+QColor HYDROData_Tool::GenerateRandColor()
+{
+  float aHue = ( rand()%1000 ) * 0.001f;
+
+  QColor aColor;
+  aColor.setHsl( (int)(aHue*255.), 200, 128 );
+  int r = aColor.red();
+  int g = aColor.green();
+  int b = aColor.blue();
+  return ( aColor.isValid() ? aColor : Qt::darkBlue );
+}
+
+void HYDROData_Tool::GenerateRepeatableRandColors(int nbColorsToGen, QVector<QColor>& theColors)
+{
+  for (int i = 1; i <= nbColorsToGen; i++)
+    theColors.append(HYDROData_Tool::GenerateRandColor());
+}
+
+bool HYDROData_Tool::GenerateNonRepeatableRandColors(int nbColorsToGen, QVector<QColor>& theColors)
+{
+  if (nbColorsToGen > aMaxColorNb)
+    return false;
+  QSet<int> Codes;
+  float aHue;
+  theColors.clear();
+  do 
+  {
+    QColor aColor;
+    int H = rand()%360;
+    int S = rand()%256;
+    int Code = H*256+S;
+    if (Codes.contains(Code))
+      continue;
+    aColor.setHsl( H, S, 128 );
+    if (aColor.isValid())
+    {
+      theColors.append(aColor);
+      Codes.insert(Code);
+    }
+  } while (theColors.size() <= nbColorsToGen);
+  return true;
+}
+
+
 bool HYDROData_Tool::IsNan( double theValue )
 {
 #ifdef WIN32
index 25bcf370861ee194a4fe7746a8db10e9648f51c9..d1f6dbdf87d7395488e7e617bd1e527f6adfed55 100644 (file)
@@ -22,6 +22,7 @@
 #include "HYDROData.h"
 #include <QStringList>
 #include <Precision.hxx>
+#include <QVector>
 
 class HYDROData_Document;
 class HYDROData_Entity;
@@ -41,6 +42,7 @@ class TopoDS_Face;
 class TopoDS_Shape;
 class TopoDS_Wire;
 class Quantity_Color;
+class QColor;
 
 class HYDRODATA_EXPORT HYDROData_Tool {
 
@@ -96,8 +98,8 @@ public:
   * Computes Point State from TopAbs (simplified & limited method).
   */
 
- static TopAbs_State                    ComputePointState( const gp_XY& thePnt2d, 
-                                                              const TopoDS_Face& theFace );
 static TopAbs_State                    ComputePointState( const gp_XY& thePnt2d, 
+                                                           const TopoDS_Face& theFace );
 
   static double GetAltitudeForEdge( const TopoDS_Edge& theEdge,
                                     const gp_XY& thePoint,
@@ -124,6 +126,10 @@ public:
   static Quantity_Color toOccColor( const QColor& );
   static QColor toQtColor( const Quantity_Color& );
 
+  static QColor GenerateRandColor();
+  static bool GenerateNonRepeatableRandColors(int nbColorsToGen, QVector<QColor>& theColors);
+  static void GenerateRepeatableRandColors(int nbColorsToGen, QVector<QColor>& theColors);
+
   static bool IsNan( double theValue );
   static bool IsInf( double theValue );
 
index 4fefda300000b6d9f027f5fd72555739e51c7ff7..baaa2485210ad657c196ce6bc25142f5c01751ef 100644 (file)
@@ -1099,8 +1099,7 @@ void HYDROGUI_CalculationOp::AssignDefaultZonesColors()
     {
       Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
       if ( !aCtx.IsNull() )
-      {
-        int aCounter = 0;        
+      {     
         for ( ; aRegionsIter.More(); aRegionsIter.Next() )
         {
           aRegion = Handle(HYDROData_Region)::DownCast( aRegionsIter.Value() );
@@ -1114,9 +1113,9 @@ void HYDROGUI_CalculationOp::AssignDefaultZonesColors()
               Handle(HYDROData_Zone) aZone = Handle(HYDROData_Zone)::DownCast( aZonesIter.Value() );
               if ( !aZone.IsNull() )
               {
-                QColor aFillingColor = GenerateDefaultZonesColor(++aCounter);
+                QColor aFillingColor = HYDROData_Tool::GenerateRandColor();
                 while (aFillingColor == Qt::red)
-                  aFillingColor = GenerateDefaultZonesColor(++aCounter);
+                  aFillingColor = HYDROData_Tool::GenerateRandColor();
                 
                 aZone->SetColor(aFillingColor);
               }
@@ -1128,20 +1127,6 @@ void HYDROGUI_CalculationOp::AssignDefaultZonesColors()
   }
 }
 
-QColor HYDROGUI_CalculationOp::GenerateDefaultZonesColor( int theIndex,
-                                                          float theSaturation/* = 0.5*/,
-                                                          float theValue/* = 0.95*/ ) const
-{
-  float aHue = ( rand()%1000 ) * 0.001f;
-
-  QColor aColor;
-  aColor.setHsl( (int)(aHue*255.), 128, 128 );
-  int r = aColor.red();
-  int g = aColor.green();
-  int b = aColor.blue();
-  return ( aColor.isValid() ? aColor : Qt::darkBlue );
-}
-
 void HYDROGUI_CalculationOp::setRules( HYDROData_CalculationCase::DataTag theDataTag )
 {
   HYDROGUI_CalculationDlg* aPanel = 
index 90cf82d1ef01edf92c7d42c1c921667e6211d693..2f46cb393ccc9f276c96770099300886f409b1cd 100644 (file)
@@ -143,22 +143,6 @@ private:
    * Internal method that used to assign unique default colors for zones
    */
   void                            AssignDefaultZonesColors();
-  /**
-   * Internal method that used to generate default color for zone
-   * @param theIndex the index of color to be generated
-   * @param theSaturation the saturation of the color in the range 0 to 1,
-   * and the bigger it is, the stronger the color is. Grayish colors have
-   * saturation near 0, very strong colors have saturation near 1.
-   * The defalt value is 0.5.
-   * @param theValue the value in the range 0 to 1, represents lightness or
-   * brightness of the color. 0 is black, 1 is as far from black as possible.
-   * The defalt value is 0.95.
-   * \return the generated color
-   */
-  QColor                          GenerateDefaultZonesColor( int theIndex,
-                                                             float theSaturation = 0.5,
-                                                             float theValue = 0.95 ) const;
-
   void                            setRules( HYDROData_CalculationCase::DataTag theDataTag );
 
   bool                            createRegion( const QList<SUIT_DataObject*>& theZonesList );
index 8ea0425935f15f77409397104cffd02be36995eb..2ef728a665b4799e2d2abb412d20b01fe9c0c9d0 100644 (file)
@@ -179,7 +179,7 @@ bool HYDROGUI_CurveCreatorProfile::addPointsInternal( const CurveCreator::Sectio
   }
 
   if ( res )
-    redisplayCurve();
+    redisplayCurve(false);
 
   return res;
 }
@@ -210,7 +210,7 @@ bool HYDROGUI_CurveCreatorProfile::setPointInternal( const CurveCreator::Section
 
   aRes = addPointsInternal( theSectionsMap );
   if ( aRes )
-    redisplayCurve();
+    redisplayCurve(false);
 
   return aRes;
 }
index b8e744ad86a62161cb693e73fd0905a215750a24..ff078d9f2e359c6313b7c77d59fef09538a22743 100644 (file)
@@ -495,7 +495,7 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
         Handle(HYDROData_Stream) aStream = 
           Handle(HYDROData_Stream)::DownCast( anObject );
         if ( !aStream.IsNull() )
-            isStreamHasBottom = !aStream->GetBottomPolyline().IsNull();
+          isStreamHasBottom = !aStream->GetBottomPolyline().IsNull();
       }
       else if( anObjectKind == KIND_CHANNEL )
         anIsChannel = true;
@@ -513,7 +513,7 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
 
   // Check if all selected objects are profiles
   anAllAreProfiles = ( aNbOfSelectedProfiles > 0 ) &&
-                     ( aNbOfSelectedProfiles == aSeq.Length() );
+    ( aNbOfSelectedProfiles == aSeq.Length() );
 
   // check the selected partitions
   if( !anIsSelectedDataObjects && anIsObjectBrowser )
@@ -523,50 +523,50 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
     {
       switch( aSelectedPartition )
       {
-        case KIND_IMAGE:
-          theMenu->addAction( action( ImportImageId ) );
-          break;
-        case KIND_BATHYMETRY:
-          theMenu->addAction( action( ImportBathymetryId ) );
-          break;
-        case KIND_ARTIFICIAL_OBJECT:
-          theMenu->addAction( action( CreateChannelId ) );
-          theMenu->addAction( action( CreateDigueId ) );
-          break;
-        case KIND_NATURAL_OBJECT:
-          theMenu->addAction( action( CreateImmersibleZoneId ) );
-          theMenu->addAction( action( CreateStreamId ) );
-          break;
-        case KIND_OBSTACLE:
-          theMenu->addAction( action( ImportObstacleFromFileId ) );
-          theMenu->addAction( action( CreateBoxId ) );
-          theMenu->addAction( action( CreateCylinderId ) );
-          break;
-        case KIND_STRICKLER_TABLE:
-          theMenu->addAction( action( ImportStricklerTableFromFileId ) );          
-          break;
-        case KIND_LAND_COVER_MAP:
-          theMenu->addAction( action( CreateLandCoverMapId ) ); 
-          theMenu->addAction( action( ImportLandCoverMapId ) ); 
-          break;
-        case KIND_CALCULATION:
-          theMenu->addAction( action( CreateCalculationId ) );
-          break;
-        case KIND_POLYLINEXY:
-          theMenu->addAction( action( ImportPolylineId ) );
-          theMenu->addAction( action( CreatePolylineId ) );
-          break;
-        case KIND_POLYLINE:
-          theMenu->addAction( action( CreatePolyline3DId ) );
-          break;
-        case KIND_PROFILE:
-          theMenu->addAction( action( CreateProfileId ) );
-          theMenu->addAction( action( ImportProfilesId ) );
-          theMenu->addAction( action( AllGeoreferencementId ) );
-          break;
-        case KIND_VISUAL_STATE:
-          theMenu->addAction( action( SaveVisualStateId ) );
-          break;
+      case KIND_IMAGE:
+        theMenu->addAction( action( ImportImageId ) );
+        break;
+      case KIND_BATHYMETRY:
+        theMenu->addAction( action( ImportBathymetryId ) );
+        break;
+      case KIND_ARTIFICIAL_OBJECT:
+        theMenu->addAction( action( CreateChannelId ) );
+        theMenu->addAction( action( CreateDigueId ) );
+        break;
+      case KIND_NATURAL_OBJECT:
+        theMenu->addAction( action( CreateImmersibleZoneId ) );
+        theMenu->addAction( action( CreateStreamId ) );
+        break;
+      case KIND_OBSTACLE:
+        theMenu->addAction( action( ImportObstacleFromFileId ) );
+        theMenu->addAction( action( CreateBoxId ) );
+        theMenu->addAction( action( CreateCylinderId ) );
+        break;
+      case KIND_STRICKLER_TABLE:
+        theMenu->addAction( action( ImportStricklerTableFromFileId ) );          
+        break;
+      case KIND_LAND_COVER_MAP:
+        theMenu->addAction( action( CreateLandCoverMapId ) ); 
+        theMenu->addAction( action( ImportLandCoverMapId ) ); 
+        break;
+      case KIND_CALCULATION:
+        theMenu->addAction( action( CreateCalculationId ) );
+        break;
+      case KIND_POLYLINEXY:
+        theMenu->addAction( action( ImportPolylineId ) );
+        theMenu->addAction( action( CreatePolylineId ) );
+        break;
+      case KIND_POLYLINE:
+        theMenu->addAction( action( CreatePolyline3DId ) );
+        break;
+      case KIND_PROFILE:
+        theMenu->addAction( action( CreateProfileId ) );
+        theMenu->addAction( action( ImportProfilesId ) );
+        theMenu->addAction( action( AllGeoreferencementId ) );
+        break;
+      case KIND_VISUAL_STATE:
+        theMenu->addAction( action( SaveVisualStateId ) );
+        break;
       }
       theMenu->addSeparator();
     }
@@ -668,8 +668,8 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
         theMenu->addAction( action( EditStreamId ) );
         if ( action( RiverBottomContextId ) )
         {
-            theMenu->addAction( action( RiverBottomContextId ) );
-            action( RiverBottomContextId )->setEnabled( !isStreamHasBottom );
+          theMenu->addAction( action( RiverBottomContextId ) );
+          action( RiverBottomContextId )->setEnabled( !isStreamHasBottom );
         }
         theMenu->addAction( action( ProfileInterpolateId ) );
         theMenu->addSeparator();
@@ -748,7 +748,10 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
         theMenu->addAction( action( SetTransparencyId ) );
         theMenu->addSeparator();
       }
-    } else if ( anAllAreProfiles ) {
+    } 
+    else if ( anAllAreProfiles )
+    {
+      theMenu->addAction( action( EditProfileId ) );
       theMenu->addAction( action( SelectedGeoreferencementId ) );
       theMenu->addSeparator();
     }
@@ -771,10 +774,10 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
     theMenu->addSeparator();
 
     if( anIsImage || anIsPolyline || anIsPolyline3D || 
-        anIsImmersibleZone || anIsZone || anIsRegion ||
-        anIsBathymetry || anIsObstacle || anIsStream ||
-        anIsChannel || anIsDigue || anIsDummyObject3D ||
-        anIsValidProfile || anIsGroup || anIsLandCoverMap )
+      anIsImmersibleZone || anIsZone || anIsRegion ||
+      anIsBathymetry || anIsObstacle || anIsStream ||
+      anIsChannel || anIsDigue || anIsDummyObject3D ||
+      anIsValidProfile || anIsGroup || anIsLandCoverMap )
     {
       if( anIsHiddenInSelection )
         theMenu->addAction( action( ShowId ) );
@@ -808,7 +811,7 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
     theMenu->addAction( action( HideAllId ) );
     theMenu->addSeparator();
   }
-  
+
   if ( anIsOCCView || anIsVTKView )
   {
     theMenu->addSeparator();
index 81cb8239a789499bef51160ccd7a48a1ea4c7fa0..d95c3e0cded3e986c1fbf4f80cd186663ec59159 100644 (file)
 #include "HYDROGUI_Module.h"
 #include "HYDROGUI_Tool.h"
 #include "HYDROGUI_AISTrihedron.h"
+#include "HYDROGUI_Tool2.h"
 
 #include <CurveCreator_Widget.h>
 #include <CurveCreator_ICurve.hxx>
 #include <CurveCreator_Utils.hxx>
+#include <HYDROGUI_CurveCreatorProfile.h>
+#include <CurveCreator_Displayer.hxx>
 
 #include <OCCViewer_ViewPort3d.h>
 #include <OCCViewer_Utilities.h>
 #include <QMouseEvent>
 #include <QSplitter>
 #include <QSettings>
+#include <QListWidget>
+#include <QPushButton>
+
 
 const QString splitter_key = "HYDROGUI_ProfileDlg::splitter";
 
-HYDROGUI_ProfileDlg::HYDROGUI_ProfileDlg( HYDROGUI_Module* theModule, const QString& theTitle )
+HYDROGUI_ProfileDlg::HYDROGUI_ProfileDlg( HYDROGUI_Module* theModule, const QString& theTitle, 
+  bool theSingleProfileMode )
 : HYDROGUI_ViewerDlg( theModule, theTitle, true ),
-  myName( NULL )
+  myName( NULL ), myProfileNames (NULL), myProfilesPointer (NULL),
+  mySingleProfileMode (theSingleProfileMode)
 {
   QFrame* name_frame = new QFrame( mainFrame() );
   QHBoxLayout* name_layout = new QHBoxLayout( name_frame );
   name_layout->setMargin( 0 );
   QLabel* aNameLabel = new QLabel(tr("PROFILE_NAME_TLT"), this);
   name_layout->addWidget(aNameLabel);
-  myName = new QLineEdit(this);
-  name_layout->addWidget(myName);
+  if (theSingleProfileMode)
+  {
+    myName = new QLineEdit(this);
+    name_layout->addWidget(myName);
+  }
+  else
+  {
+    myProfileNames = new QListWidget(this);
+    myProfileNames->setSelectionMode(QAbstractItemView::SingleSelection);
+    //myProfileNames->setEditable(true);
+    //myProfileNames->setInsertPolicy(QComboBox::InsertPolicy::NoInsert);
+    name_layout->addWidget(myProfileNames);
+    //
+    myAddProfBtn = new QPushButton("Add Profile(s)", this);    
+    myRemProfBtn = new QPushButton("Remove Profile(s)", this);
+    name_layout->addWidget(myAddProfBtn);
+    name_layout->addWidget(myRemProfBtn);
+  }
 
   insertWidget( name_frame, 0, 0 );
 
@@ -79,7 +103,14 @@ HYDROGUI_ProfileDlg::HYDROGUI_ProfileDlg( HYDROGUI_Module* theModule, const QStr
   connect( myEditorWidget, SIGNAL( selectionChanged() ), this, SIGNAL( selectionChanged() ) );
   connect( myEditorWidget, SIGNAL( subOperationStarted(QWidget*, bool) ), this, SLOT( processStartedSubOperation(QWidget*, bool) ) );
   connect( myEditorWidget, SIGNAL( subOperationFinished(QWidget*) ), this, SLOT( processFinishedSubOperation(QWidget*) ) );
-
+  if (!mySingleProfileMode)
+  {
+    //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)));
+    connect( myRemProfBtn, SIGNAL( clicked(bool)), this, SLOT( onRemoveBtnPressed(bool)));
+  }
   myAddElementBox->hide();
 
   QList<int> sizes;
@@ -109,16 +140,51 @@ void HYDROGUI_ProfileDlg::reset()
   myEditorWidget->reset();
   myEditorWidget->setActionMode( CurveCreator_Widget::AdditionMode );
   viewer()->setTrihedronShown( false ); // Issue #548
+  myProfileNames->clear();
 }
 
 void HYDROGUI_ProfileDlg::setProfileName( const QString& theName )
 {
+  if (!mySingleProfileMode)
+    return;
   myName->setText(theName);
+  //myProfileNames->setItemText(theInd, theName); //should used TODO check this
+  //myName->setText(theName);
+}
+
+void HYDROGUI_ProfileDlg::eraseProfile( int index )
+{
+  myProfileNames->takeItem(index);
 }
 
-QString HYDROGUI_ProfileDlg::getProfileName() const
+void HYDROGUI_ProfileDlg::addProfileName( const QString& theName, const QColor& theColor )
 {
-  return myName->text();
+  if (mySingleProfileMode)
+    return;
+  myProfileNames->blockSignals(true);
+  myProfileNames->addItem(theName);
+  int count = myProfileNames->count();
+  QListWidgetItem* anItem = myProfileNames->item(count - 1);
+  anItem->setFlags (anItem->flags () | Qt::ItemIsEditable);
+  QPixmap SPixmap(16, 16);
+  SPixmap.fill(theColor);
+  QIcon SIcon(SPixmap);
+  anItem->setIcon( SIcon );
+  //anItem->setBackground(QBrush(theColor));
+  if (count == 1)
+    anItem->setSelected(true);
+  myProfileNames->blockSignals(false);
+}
+
+QStringList HYDROGUI_ProfileDlg::getProfileNames() const
+{
+  QStringList aProfNames;
+  if (mySingleProfileMode)
+    aProfNames << myName->text();
+  else
+    for (int i = 0; i < myProfileNames->count(); i++)
+      aProfNames <<  myProfileNames->item(i)->text();
+  return aProfNames;
 }
 
 void HYDROGUI_ProfileDlg::setProfile( CurveCreator_ICurve* theProfile )
@@ -131,11 +197,21 @@ void HYDROGUI_ProfileDlg::setProfile( CurveCreator_ICurve* theProfile )
   myEditorWidget->setSelectedSections( aSections );
 }
 
+void HYDROGUI_ProfileDlg::setProfilesPointer(std::vector<HYDROGUI_CurveCreatorProfile*>* theProfilesPointer)
+{
+  myProfilesPointer = theProfilesPointer;
+}
+
 QList<int> HYDROGUI_ProfileDlg::getSelectedSections()
 {
   return myEditorWidget->getSelectedSections();
 }
 
+void HYDROGUI_ProfileDlg::switchToFirstProfile()
+{
+  emit onProfileIndexChanged();
+}
+
 /**
  * Redirect the delete action to editor widget
  */
@@ -175,10 +251,95 @@ void HYDROGUI_ProfileDlg::processFinishedSubOperation( QWidget* theWidget )
   myAddElementBox->hide();
 }
 
+//void HYDROGUI_ProfileDlg::ProfileNameChanged(QString theNewText)
+//{
+//  myProfileNames->setItemText( myProfileNames->currentIndex(), theNewText ); //TODO???
+//}
+
+void HYDROGUI_ProfileDlg::onProfileIndexChanged()
+{
+  int theIndex = GetProfileSelectionIndex();
+  if (theIndex > -1)
+    SwitchToProfile(theIndex);
+}
+
+int HYDROGUI_ProfileDlg::GetProfileSelectionIndex()
+{
+  if (!myProfilesPointer)
+    return -1;
+  QModelIndexList MI = myProfileNames->selectionModel()->selectedIndexes();
+  if (MI.size() != 1)
+    return -1;
+  return MI.first().row();
+}
+
+void HYDROGUI_ProfileDlg::BlockProfileNameSignals(bool state)
+{
+  myProfileNames->blockSignals(state);
+}
+
+void HYDROGUI_ProfileDlg::SwitchToProfile(int theIndex)
+{
+  myEditorWidget->setCurve(NULL);
+  myEditorWidget->reset();
+  myEditorWidget->setActionMode( CurveCreator_Widget::AdditionMode );
+  myEditorWidget->setSelectedSections(QList<int>());
+  setProfile( (*myProfilesPointer)[theIndex] );
+  for (int i = 0; i < myProfilesPointer->size(); i++)
+  {
+    HYDROGUI_CurveCreatorProfile* aCurve = (*myProfilesPointer)[i];
+    if (i == theIndex)
+    {
+      aCurve->myLineWidth = 3;
+      Handle(AIS_InteractiveObject) anAISObject = aCurve->getAISObject();
+      if (anAISObject)
+        anAISObject->SetWidth(3);
+    }
+    else
+    {
+      aCurve->myLineWidth = 1;
+      Handle(AIS_InteractiveObject) anAISObject = aCurve->getAISObject();
+      if (anAISObject)
+        anAISObject->SetWidth(1);
+    }
+  }
+  (*myProfilesPointer)[0]->getDisplayer()->Update();
+}
+
+void HYDROGUI_ProfileDlg::onAddBtnPressed(bool)
+{ 
+  emit AddProfiles();
+}
+
+void HYDROGUI_ProfileDlg::onRemoveBtnPressed(bool)
+{
+  int theIndex = GetProfileSelectionIndex();
+  if (theIndex > -1)
+    emit RemoveProfile(theIndex);
+}
+
+void HYDROGUI_ProfileDlg::onProfileNameChanged(QListWidgetItem* item)
+{
+  int ind = GetProfileSelectionIndex();
+  //if (ind > -1)
+    //TODO
+  QString text = item->text();
+}
+
+void HYDROGUI_ProfileDlg::SetSingleProfileMode(bool SingleMode)
+{
+  mySingleProfileMode = SingleMode;
+}
+
+bool HYDROGUI_ProfileDlg::GetSingleProfileMode() const
+{
+  return mySingleProfileMode;
+}
+
 Handle(AIS_Trihedron) HYDROGUI_ProfileDlg::trihedron()
 {
-    SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
-    Handle(AIS_Trihedron) aTrihedron =
-        HYDROGUI_AISTrihedron::createTrihedron( aResMgr->doubleValue( "3DViewer", "trihedron_size", viewer()->trihedronSize() ) );
-    return aTrihedron;
+  SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
+  Handle(AIS_Trihedron) aTrihedron =
+    HYDROGUI_AISTrihedron::createTrihedron( aResMgr->doubleValue( "3DViewer", "trihedron_size", viewer()->trihedronSize() ) );
+  return aTrihedron;
 }
index 1b41ae1d08ffd8cf183506800ad889e325ff4719..d8705434da91f2ae06a881c6219af9fec3ce6b3a 100644 (file)
@@ -22,6 +22,7 @@
 #include "HYDROGUI_ViewerDlg.h"
 
 #include <AIS_InteractiveContext.hxx>
+#include <vector>
 
 class CurveCreator_Widget;
 class CurveCreator_ICurve;
@@ -30,19 +31,32 @@ class SUIT_ViewWindow;
 class QGroupBox;
 class QLineEdit;
 class QLabel;
+class QListWidget;
+class HYDROGUI_CurveCreatorProfile;
+class HYDROData_SequenceOfObjects; 
+class QListWidgetItem;
 
 class HYDROGUI_ProfileDlg : public HYDROGUI_ViewerDlg
 {
   Q_OBJECT
 
 public:
-  HYDROGUI_ProfileDlg( HYDROGUI_Module* theModule, const QString& theTitle );
+  HYDROGUI_ProfileDlg( HYDROGUI_Module* theModule, const QString& theTitle, bool theSingleProfileMode );
   virtual ~HYDROGUI_ProfileDlg();
 
-  void  setProfileName( const QString& theName );
-  QString getProfileName() const;
+  void setProfileName( const QString& theName );
+  void addProfileName( const QString& theName, const QColor& theColor );
+  void eraseProfile( int index );
+  QStringList getProfileNames() const;
        
   void  setProfile( CurveCreator_ICurve* theProfile );
+  void  setProfilesPointer(std::vector<HYDROGUI_CurveCreatorProfile*>* theProfilesPointer);
+  void  switchToFirstProfile();
+  void  SetSingleProfileMode(bool SingleMode);
+  bool  GetSingleProfileMode() const;
+  void  SwitchToProfile(int theIndex);
+  void  BlockProfileNameSignals(bool state);
+  int   GetProfileSelectionIndex();
 
   void  reset();
 
@@ -54,6 +68,11 @@ public:
 protected slots:
   void processStartedSubOperation( QWidget*, bool );
   void processFinishedSubOperation( QWidget* );
+  //void ProfileNameChanged(QString);
+  void onProfileIndexChanged();
+  void onAddBtnPressed(bool);
+  void onRemoveBtnPressed(bool);
+  void onProfileNameChanged(QListWidgetItem* item);
 
 signals:
   void                  createPreview( QString );
@@ -61,14 +80,23 @@ signals:
   void                  widgetCreated(QWidget*);
   void                  subOperationStarted(QWidget*);
   void                  subOperationFinished(QWidget*);
+  void                  AddProfiles();
+  void                  RemoveProfile(int);
+
 
 protected:
   virtual Handle(AIS_Trihedron) trihedron();
 
 private:
   QLineEdit*             myName;
+  QListWidget*           myProfileNames;
+  QPushButton*           myAddProfBtn;
+  QPushButton*           myRemProfBtn; 
+public://temp TODO
   CurveCreator_Widget*   myEditorWidget;
   QGroupBox*             myAddElementBox;
+  std::vector<HYDROGUI_CurveCreatorProfile*>* myProfilesPointer;
+  bool                   mySingleProfileMode;
 };
 
 #endif
index 732637ac6fff4743b91d5caf9b0efed484960130..7bbae5ff3653ad203458c43ef13c65282e116712 100644 (file)
 #include <HYDROData_Profile.h>
 #include <HYDROGUI_CurveCreatorProfile.h>
 #include <HYDROGUI_DeleteOp.h>
+#include <HYDROData_Tool.h>
 #include <CurveCreator_Displayer.hxx>
+#include <HYDROData_Entity.h>
+#include <QSet>
 
 #include <LightApp_Application.h>
 #include <LightApp_SelectionMgr.h>
 
 //static int ZValueIncrement = 0;
 
+static void ProfileUZToCurveCrProfile(const Handle(HYDROData_ProfileUZ)& aProfileUZ, 
+  HYDROGUI_CurveCreatorProfile* outProfile)
+{
+  CurveCreator::Coordinates aCurveCoords;
+  CurveCreator::SectionsMap aSectionsMap;
+
+  HYDROData_ProfileUZ::PointsList aSectPointsList = aProfileUZ->GetPoints();
+  CurveCreator::PosPointsList aPoints;
+  for ( int k = 1, aNbPoints = aSectPointsList.Size(); k <= aNbPoints; ++k )
+  {
+    const HYDROData_ProfileUZ::Point& aSectPoint = aSectPointsList.Value( k );
+    aCurveCoords.clear();
+    aCurveCoords.push_back( aSectPoint.X() );
+    aCurveCoords.push_back( aSectPoint.Y() );
+
+    CurveCreator_PosPoint* aPosPoint = new CurveCreator_PosPoint( k, aCurveCoords );
+    aPoints.push_back( aPosPoint );
+  }
+
+  aSectionsMap[0] = aPoints;
+  outProfile->addPointsInternal( aSectionsMap );
+
+  HYDROData_ProfileUZ::SectionType aSectType = aProfileUZ->GetSectionType( 0 );
+
+  CurveCreator::SectionType aCurveType = CurveCreator::Polyline;
+  if( aSectType == HYDROData_ProfileUZ::SECTION_SPLINE )
+    aCurveType = CurveCreator::Spline;
+
+  outProfile->setSectionType( 0, aCurveType );
+}
+
+static int CurveCrProfileToHProfile(const HYDROGUI_CurveCreatorProfile* outProfile, 
+  Handle(HYDROData_Profile) theProfileObj,
+  const QString theProfileName,
+  bool IsEdit)
+{
+  if( theProfileObj.IsNull() )
+    return 0;
+
+  Handle(HYDROData_ProfileUZ) aProfileUZ = theProfileObj->GetProfileUZ();
+  if ( aProfileUZ.IsNull() )
+    return 0;
+
+  theProfileObj->SetName(theProfileName);
+
+  HYDROData_ProfileUZ::PointsList aProfileParamPoints;
+
+  Handle(TColgp_HArray1OfPnt) aCurveCoords = outProfile->GetDifferentPoints( 0 );
+  if ( aCurveCoords.IsNull() || aCurveCoords->Size() <= 2 )
+    return -1;
+
+  for ( int k = aCurveCoords->Lower(); k <= aCurveCoords->Upper() ; k++ )
+  {
+    HYDROData_ProfileUZ::Point aProfileParamPoint;
+
+    aProfileParamPoint.SetX( aCurveCoords->Value( k ).X() );
+    aProfileParamPoint.SetY( aCurveCoords->Value( k ).Y() );
+
+    aProfileParamPoints.Append( aProfileParamPoint );
+  }
+  theProfileObj->SetParametricPoints( aProfileParamPoints );
+
+  HYDROData_ProfileUZ::SectionType aSectType = HYDROData_ProfileUZ::SECTION_POLYLINE;
+  if ( outProfile->getSectionType( 0 ) == CurveCreator::Spline )
+    aSectType = HYDROData_ProfileUZ::SECTION_SPLINE;
+
+  aProfileUZ->SetSectionType( 0, aSectType );
+
+  if ( !IsEdit )
+    theProfileObj->SetBorderColor( theProfileObj->DefaultBorderColor() );
+
+  // At first we update the child u,z profile object
+  aProfileUZ->Changed( HYDROData_Entity::Geom_2d );
+  aProfileUZ->Update();
+
+  // And now we update our edited object
+  theProfileObj->Update();
+  return 1;
+}
+
 HYDROGUI_ProfileOp::HYDROGUI_ProfileOp( HYDROGUI_Module* theModule, bool theIsEdit )
-: HYDROGUI_Operation( theModule ), myIsEdit(theIsEdit), myProfile(NULL)
+: HYDROGUI_Operation( theModule ), myIsEdit(theIsEdit), 
+   myDisplayer (NULL), mySingleProfileMode (false)
 {
   setName( theIsEdit ? tr( "EDIT_PROFILE" ) : tr( "CREATE_PROFILE" ) );
 }
@@ -65,6 +149,7 @@ void HYDROGUI_ProfileOp::deleteSelected()
 /**
  * Checks whether there are some to delete
  */
+#include <CurveCreator_Widget.h>
 bool HYDROGUI_ProfileOp::deleteEnabled()
 {
   HYDROGUI_ProfileDlg* aPanel = (HYDROGUI_ProfileDlg*)inputPanel();
@@ -73,66 +158,160 @@ bool HYDROGUI_ProfileOp::deleteEnabled()
 
 void HYDROGUI_ProfileOp::startOperation()
 {
-  if( myProfile )
-    delete myProfile;
+  if (!myProfiles.empty())
+  {
+    for (int i = 0; i < myProfiles.size(); i++)
+    {
+      delete myProfiles[i];
+      myProfiles[i] = NULL;
+    }
+    myProfiles.clear();
+  }
+
+  if (!myIsEdit)
+    myEditedObjects.Clear();
 
-  myProfile = new HYDROGUI_CurveCreatorProfile();
+  if (myCurveToProfile.IsEmpty())
+    myCurveToProfile.Clear();
 
+  if( myIsEdit && isApplyAndClose() )
+    myEditedObjects = HYDROGUI_Tool::GetSelectedObjects(module());
+
+  int lenP = myEditedObjects.Length();  
+  myProfiles.resize(lenP == 0 ? 1 : myEditedObjects.Length());
+  for (int i = 0; i < myProfiles.size(); i++)
+    myProfiles[i] = new HYDROGUI_CurveCreatorProfile();
+
+  mySingleProfileMode = myEditedObjects.IsEmpty() || lenP == 1;  
   HYDROGUI_Operation::startOperation();
 
   HYDROGUI_ProfileDlg* aPanel = (HYDROGUI_ProfileDlg*)inputPanel();
+  aPanel->myEditorWidget->setCurve(NULL);
   aPanel->reset();
   setPreviewManager( aPanel->viewManager() );
   setCursor();
 
-  if( myIsEdit )
-    if ( isApplyAndClose() )
-      myEditedObject = Handle(HYDROData_Profile)::DownCast( HYDROGUI_Tool::GetSelectedObject( module() ) );
-
-  QString aProfileName;
-  if( !myEditedObject.IsNull() )
+  aPanel->SetSingleProfileMode(mySingleProfileMode); 
+  QMap<HYDROGUI_CurveCreatorProfile*, QColor> CurveToColor;
+  if( lenP )
   {
-    Handle(HYDROData_ProfileUZ) aProfileUZ = myEditedObject->GetProfileUZ( false );
-    if ( !aProfileUZ.IsNull() )
+    for (int i = 1; i <= lenP; i++)
     {
-      CurveCreator::Coordinates aCurveCoords;
-      CurveCreator::SectionsMap aSectionsMap;
-
-      HYDROData_ProfileUZ::PointsList aSectPointsList = aProfileUZ->GetPoints();
-      CurveCreator::PosPointsList aPoints;
-      for ( int k = 1, aNbPoints = aSectPointsList.Size(); k <= aNbPoints; ++k )
+      Handle(HYDROData_Profile) aCProfile = Handle(HYDROData_Profile)::DownCast(myEditedObjects(i)); 
+      QString aProfileName;
+      if( !aCProfile.IsNull() )
       {
-        const HYDROData_ProfileUZ::Point& aSectPoint = aSectPointsList.Value( k );
-        aCurveCoords.clear();
-        aCurveCoords.push_back( aSectPoint.X() );
-        aCurveCoords.push_back( aSectPoint.Y() );
-
-        CurveCreator_PosPoint* aPosPoint = new CurveCreator_PosPoint( k, aCurveCoords );
-        aPoints.push_back( aPosPoint );
+        Handle(HYDROData_ProfileUZ) aProfileUZ = aCProfile->GetProfileUZ( false );
+        if ( !aProfileUZ.IsNull() )
+        {
+          HYDROGUI_CurveCreatorProfile* CP = new HYDROGUI_CurveCreatorProfile();
+          myProfiles[i-1] = CP;
+          ProfileUZToCurveCrProfile(aProfileUZ, CP);
+          myCurveToProfile.Bind(CP, aCProfile);
+        }
       }
+    }
+    int ext = myCurveToProfile.Extent(); //ext should be equal to lenP
+    QVector<QColor> PColors;
+    if (!mySingleProfileMode)
+      HYDROData_Tool::GenerateRepeatableRandColors(ext, PColors);
+    else
+      PColors << QColor(0,0,255); //default color
+
+    for (int i = 0; i < myProfiles.size(); i++)
+    {
+      HYDROGUI_CurveCreatorProfile* CC = myProfiles[i];
+      const Handle(HYDROData_Profile)& CP = myCurveToProfile.Find(CC);
+      const QColor& CurCol = PColors[i]; 
+      CurveToColor[CC] = CurCol;
+      const QString& profName = CP->GetName();
+      const QColor& PColor = CurCol;
+      if (!mySingleProfileMode)
+        aPanel->addProfileName(profName, PColor);
+      else
+        aPanel->setProfileName(profName);
+    }
+  }
 
-      aSectionsMap[0] = aPoints;
-      myProfile->addPointsInternal( aSectionsMap );
+  if (!myIsEdit)
+  {
+    QString aProfileName = HYDROGUI_Tool::GenerateObjectName( module(), tr( "DEFAULT_PROFILE_NAME" ) );
+    aPanel->setProfileName( aProfileName );
+  }
 
-      HYDROData_ProfileUZ::SectionType aSectType = aProfileUZ->GetSectionType( 0 );
+  if (!myProfiles.empty())
+  {
+    aPanel->setProfile( myProfiles[0] );
+    aPanel->setProfilesPointer( &myProfiles );
+  }
+  displayPreviews(CurveToColor, 0, myProfiles.size(), true, true );
+}
 
-      CurveCreator::SectionType aCurveType = CurveCreator::Polyline;
-      if( aSectType == HYDROData_ProfileUZ::SECTION_SPLINE )
-        aCurveType = CurveCreator::Spline;
+void HYDROGUI_ProfileOp::onAddProfiles()
+{
+  if( !myIsEdit )
+    return;
 
-      myProfile->setSectionType( 0, aCurveType );
-    }
+  QSet<QString> edObjNamesMap;
+  for (int i = 1; i <= myEditedObjects.Length(); i++)
+    edObjNamesMap.insert( myEditedObjects(i)->GetName());
 
-    aProfileName = myEditedObject->GetName();
-  }
-  else
+  HYDROData_SequenceOfObjects aSelectedObj = HYDROGUI_Tool::GetSelectedObjects( module() );;
+  int ExistingProfLen = myEditedObjects.Length();
+  for (int i = 1; i <= aSelectedObj.Length(); i++)
   {
-    aProfileName = HYDROGUI_Tool::GenerateObjectName( module(), tr( "DEFAULT_PROFILE_NAME" ) );
+    Handle(HYDROData_Entity) CurProf = Handle(HYDROData_Entity)::DownCast(aSelectedObj(i));
+    if (CurProf.IsNull())
+      continue;
+    if (!edObjNamesMap.contains(CurProf->GetName()))
+      myEditedObjects.Append(CurProf);
   }
 
-  aPanel->setProfileName( aProfileName );
-  aPanel->setProfile( myProfile );
-  displayPreview();
+  int NewLen = myEditedObjects.Length();
+  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 )
+  {
+    //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() )
+      {
+        Handle(HYDROData_ProfileUZ) aProfileUZ = aCProfile->GetProfileUZ( false );
+        if ( !aProfileUZ.IsNull() )
+        {
+          HYDROGUI_CurveCreatorProfile* CP = new HYDROGUI_CurveCreatorProfile();
+          myProfiles[i-1] = CP;
+          ProfileUZToCurveCrProfile(aProfileUZ, CP);
+          myCurveToProfile.Bind(CP, aCProfile);            
+        }
+      }
+    }
+    //int ext = myCurveToProfile.Extent(); //ext should be equal to lenP
+    QVector<QColor> PColors;
+    HYDROData_Tool::GenerateRepeatableRandColors(NewLen - ExistingProfLen, PColors);
+
+    for (int i = ExistingProfLen; i < NewLen; i++)
+    {
+      HYDROGUI_CurveCreatorProfile* CC = myProfiles[i];
+      const Handle(HYDROData_Profile)& CP = myCurveToProfile.Find(CC);
+      const QColor& CurCol = PColors[i-ExistingProfLen]; 
+      CurveToColor[CC] = CurCol;
+      const QString& profName = CP->GetName();
+      const QColor& PColor = CurCol;
+      if (!mySingleProfileMode)
+        aPanel->addProfileName(profName, PColor);
+      else
+        aPanel->setProfileName(profName);
+    }
+  }
+  displayPreviews(CurveToColor, ExistingProfLen, NewLen, false, false);
 }
 
 void HYDROGUI_ProfileOp::abortOperation()
@@ -153,7 +332,11 @@ void HYDROGUI_ProfileOp::commitOperation()
 
 HYDROGUI_InputPanel* HYDROGUI_ProfileOp::createInputPanel() const
 {
-  HYDROGUI_ProfileDlg* aDlg = new HYDROGUI_ProfileDlg( module(), getName() );
+  HYDROGUI_ProfileDlg* aDlg = new HYDROGUI_ProfileDlg( module(), getName(), mySingleProfileMode );
+  connect( aDlg, SIGNAL( AddProfiles() ), this, 
+    SLOT( onAddProfiles() ) );
+  connect( aDlg, SIGNAL( RemoveProfile(int) ), this, 
+    SLOT( onRemoveProfile(int) ) );  
   return aDlg;
 }
 
@@ -165,95 +348,67 @@ bool HYDROGUI_ProfileOp::processApply( int& theUpdateFlags,
   if ( !aPanel )
     return false;
 
-  QString aProfileName = aPanel->getProfileName().simplified();
-  if ( aProfileName.isEmpty() )
+  QStringList aProfileNames = aPanel->getProfileNames();
+  QVector<QString> aProfileNamesFiltered;
+  int i = 0;
+  foreach (QString profName, aProfileNames)
   {
-    theErrorMsg = tr( "INCORRECT_OBJECT_NAME" );
-    return false;
-  }
-
-  if( !myIsEdit || ( !myEditedObject.IsNull() && myEditedObject->GetName() != aProfileName ) )
-  {
-    // check that there are no other objects with the same name in the document
-    Handle(HYDROData_Entity) anObject = HYDROGUI_Tool::FindObjectByName( module(), aProfileName );
-    if( !anObject.IsNull() )
+    i++;
+    if ( profName.isEmpty() )
     {
-      theErrorMsg = tr( "OBJECT_EXISTS_IN_DOCUMENT" ).arg( aProfileName );
-      return false;
+      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;
+    }
+    aProfileNamesFiltered.append(profName);
   }
-
-  Handle(HYDROData_Profile) aProfileObj;
-  if( myIsEdit ){
-    aProfileObj = myEditedObject;
-  }
-  else{
-    aProfileObj = Handle(HYDROData_Profile)::DownCast( doc()->CreateObject( KIND_PROFILE ) );
-  }
-
-  if( aProfileObj.IsNull() )
-    return false;
-
-  Handle(HYDROData_ProfileUZ) aProfileUZ = aProfileObj->GetProfileUZ();
-  if ( aProfileUZ.IsNull() )
-    return false;
-
-  aProfileObj->SetName(aProfileName);
-
-  HYDROData_ProfileUZ::PointsList aProfileParamPoints;
-
-  Handle(TColgp_HArray1OfPnt) aCurveCoords = myProfile->GetDifferentPoints( 0 );
-  if ( aCurveCoords.IsNull() || aCurveCoords->Size() <= 2 )
-  {
-    theErrorMsg = tr( "NUMBER_OF_PROFILE_POINTS_INCORRECT" );
-    return false;
-  }
-
-  for ( int k = aCurveCoords->Lower(); k <= aCurveCoords->Upper() ; k++ )
-  {
-    HYDROData_ProfileUZ::Point aProfileParamPoint;
-
-    aProfileParamPoint.SetX( aCurveCoords->Value( k ).X() );
-    aProfileParamPoint.SetY( aCurveCoords->Value( k ).Y() );
-
-    aProfileParamPoints.Append( aProfileParamPoint );
-  }
-  aProfileObj->SetParametricPoints( aProfileParamPoints );
-
-  HYDROData_ProfileUZ::SectionType aSectType = HYDROData_ProfileUZ::SECTION_POLYLINE;
-  if ( myProfile->getSectionType( 0 ) == CurveCreator::Spline )
-    aSectType = HYDROData_ProfileUZ::SECTION_SPLINE;
-
-  aProfileUZ->SetSectionType( 0, aSectType );
-
-  if ( !myIsEdit )
-  {
-    aProfileObj->SetBorderColor( aProfileObj->DefaultBorderColor() );
-  }
-
-  // At first we update the child u,z profile object
-  aProfileUZ->Changed( HYDROData_Entity::Geom_2d );
-  aProfileUZ->Update();
-
-  // And now we update our edited object
-  aProfileObj->Update();
-  module()->setIsToUpdate( aProfileObj );
-
+  //  
   theUpdateFlags = UF_Model;
-  if ( myIsEdit )
+  if (myIsEdit)
+  {
+    for (int i = 1; i <= myEditedObjects.Size(); i++)
+    {
+      Handle(HYDROData_Profile) HProf = Handle(HYDROData_Profile)::DownCast(myEditedObjects(i));
+      int stat = CurveCrProfileToHProfile(myProfiles[i-1], HProf, aProfileNamesFiltered[i-1], true);
+      if (stat == 0)
+        continue;
+      else if (stat == -1)
+      {    
+        theErrorMsg = tr( "NUMBER_OF_PROFILE_POINTS_INCORRECT" ); //TODO resolve this
+        continue;
+      }    
+      module()->setIsToUpdate( HProf );
+    }
     theUpdateFlags |= UF_OCCViewer | UF_OCC_Forced | UF_VTKViewer;
+  }
   else
   {
-    QString anEntry = HYDROGUI_DataObject::dataObjectEntry( aProfileObj );
+    Handle(HYDROData_Profile) aNewProfileObj = Handle(HYDROData_Profile)::DownCast( doc()->CreateObject( KIND_PROFILE ) ); 
+    int stat = CurveCrProfileToHProfile(myProfiles[0], aNewProfileObj, aProfileNamesFiltered[0], false);
+    if (stat == 0)
+      return false;
+    else if (stat == -1)
+    {    
+      theErrorMsg = tr( "NUMBER_OF_PROFILE_POINTS_INCORRECT" );
+      return false;
+    }    
+    module()->setIsToUpdate( aNewProfileObj );
+    QString anEntry = HYDROGUI_DataObject::dataObjectEntry( aNewProfileObj );
     theBrowseObjectsEntries.append( anEntry );
   }
 
   return true;
 }
 
-void HYDROGUI_ProfileOp::displayPreview()
+/*void HYDROGUI_ProfileOp::displayPreview()
 {
-  HYDROGUI_ProfileDlg* aPanel = dynamic_cast<HYDROGUI_ProfileDlg*>( inputPanel() );
/* HYDROGUI_ProfileDlg* aPanel = dynamic_cast<HYDROGUI_ProfileDlg*>( inputPanel() );
   if( aPanel )
   {
     Handle(AIS_InteractiveContext) aCtx = aPanel->getAISContext();
@@ -264,20 +419,89 @@ void HYDROGUI_ProfileOp::displayPreview()
       aDisplayer->display( myProfile->getAISObject( true ), true );
     }
   }
+}*/
+
+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() );
+  if( aPanel )
+  {
+    Handle(AIS_InteractiveContext) aCtx = aPanel->getAISContext();
+    if( !aCtx.IsNull() )
+    {
+      if (myDisplayer)
+      {
+        //delete myDisplayer;
+        //myDisplayer = NULL;
+      }
+      if (createNewDisplayer)
+        myDisplayer = new CurveCreator_Displayer( aCtx );
+      for (int i = firstIndProf; i < lastIndProf; i++ )
+      {
+        HYDROGUI_CurveCreatorProfile* CC = myProfiles[i];
+        QColor QCurCol = QColor(0,0,255); //def color
+        if (myIsEdit)
+          QCurCol = CurveToColor[CC];
+        Quantity_Color CurOCCCol = HYDROData_Tool::toOccColor(QCurCol);
+        CC->setDisplayer( myDisplayer );
+        CC->myPointAspectColor = CurOCCCol;
+        CC->myCurveColor = CurOCCCol;
+        CC->myLineWidth = 1;
+        myDisplayer->display( CC->getAISObject( true ), true );
+      }
+    }
+    if (SwitchToFirstProf && !myProfiles.empty())
+      aPanel->switchToFirstProfile();
+  }
 }
 
 void HYDROGUI_ProfileOp::erasePreview()
 {
   HYDROGUI_ProfileDlg* aPanel = dynamic_cast<HYDROGUI_ProfileDlg*>( inputPanel() );
-  CurveCreator_Displayer* aDisplayer = myProfile ? myProfile->getDisplayer() : 0;
-  if( aPanel && aDisplayer )
+  //CurveCreator_Displayer* aDisplayer = myProfiles[0] ? myProfile[0]->getDisplayer() : 0;
+  if( aPanel && myDisplayer )
   {
     Handle(AIS_InteractiveContext) aCtx = aPanel->getAISContext();
     if( !aCtx.IsNull() )
     {
-      aDisplayer->eraseAll( true );
+      myDisplayer->eraseAll( true );
     }
   }
+  myCurveToProfile.Clear();
+}
+
+void HYDROGUI_ProfileOp::onRemoveProfile(int index)
+{
+  if (index >= myProfiles.size() )
+    return;
+
+  if (!myIsEdit)
+    return;
+
+  HYDROGUI_CurveCreatorProfile* CP = myProfiles[index];
+  myProfiles.erase (myProfiles.begin()+index);
+  myEditedObjects.Remove(index+1);
+  myCurveToProfile.UnBind(CP);
+
+  HYDROGUI_ProfileDlg* aPanel = (HYDROGUI_ProfileDlg*)inputPanel();
+  //aPanel->reset();
+  //setPreviewManager( aPanel->viewManager() );
+  //setCursor();
+
+  aPanel->BlockProfileNameSignals(true);
+  aPanel->eraseProfile(index);
+
+  Handle(AIS_InteractiveContext) aCtx = aPanel->getAISContext();
+  if( !aCtx.IsNull() && myDisplayer)
+    myDisplayer->erase( CP->getAISObject(false), true);
+  CP->SetEraseAllState(false);
+  delete CP;
+  int selectedInd = aPanel->GetProfileSelectionIndex();
+  if (selectedInd > -1)
+    aPanel->SwitchToProfile(selectedInd);
+  aPanel->BlockProfileNameSignals(false);
 }
 
 bool HYDROGUI_ProfileOp::isValid( SUIT_Operation* theOtherOp ) const
index 2d773d8e090d02658a6c396137f0dceaabecc6ca..ecdfbf13d89805ba9a55482f70612d40e91dffda 100644 (file)
 #include "HYDROGUI_Operation.h"
 
 #include <HYDROData_Profile.h>
-
+#include <vector>
+#include <QMap>
+#include <NCollection_DataMap.hxx>
+class QColor;
 class HYDROGUI_CurveCreatorProfile;
+class CurveCreator_Displayer;
 
 class HYDROGUI_ProfileOp : public HYDROGUI_Operation
 {
@@ -49,13 +53,26 @@ protected:
                                            QStringList& theBrowseObjectsEntries );
 
 private:
-  void                       displayPreview();
+  void                       displayPreviews(const QMap<HYDROGUI_CurveCreatorProfile*, QColor>& CurveToColor,
+                                             int firstIndProf, int lastIndProf, 
+                                             bool createNewDisplayer, bool SwitchToFirstProf);
+
   void                       erasePreview();
 
+
+protected slots:
+  virtual void               onAddProfiles();
+  
+  virtual void               onRemoveProfile(int index);
+
 private:
-  bool                       myIsEdit;
-  Handle(HYDROData_Profile)  myEditedObject;
-  HYDROGUI_CurveCreatorProfile* myProfile;
+  bool                        myIsEdit;
+  bool                        mySingleProfileMode;
+  HYDROData_SequenceOfObjects myEditedObjects;
+  std::vector<HYDROGUI_CurveCreatorProfile*> myProfiles;
+  CurveCreator_Displayer*                    myDisplayer;
+  NCollection_DataMap<HYDROGUI_CurveCreatorProfile*, Handle(HYDROData_Profile)> myCurveToProfile;
+
 };
 
 #endif
index 0bac9b9843522effe3fd3678cda083117253f576..8f54d1fd67ade782f050c387a39c5c260043acbe 100644 (file)
@@ -56,7 +56,7 @@
 
 void test_HYDROGUI_ProfilesDlg::test_default_size()
 {
-  HYDROGUI_ProfileDlg* dlg = new HYDROGUI_ProfileDlg( 0, "test" );
+  HYDROGUI_ProfileDlg* dlg = new HYDROGUI_ProfileDlg( 0, "test", true );
   dlg->resize( 320, 640 );
   dlg->show();
   QTest::qWaitForWindowExposed( dlg );
@@ -131,7 +131,7 @@ void setCoords( HYDROGUI_ProfileDlg* dlg, int theIndex, double theValue )
 
 void test_HYDROGUI_ProfilesDlg::test_points_table()
 {
-  HYDROGUI_ProfileDlg* dlg = new HYDROGUI_ProfileDlg( 0, "test" );
+  HYDROGUI_ProfileDlg* dlg = new HYDROGUI_ProfileDlg( 0, "test", false ); 
   dlg->resize( 320, 800 );
   dlg->setProfile( profile() );
   dlg->show();