Salome HOME
lot 12 GUI p.1
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_ProfileDlg.cxx
index c6c49c1c682b4101a07831af174d1efbc134bb1f..a60b631053fca3ec3325d9614d23dd4a9cf0e63f 100644 (file)
@@ -29,6 +29,7 @@
 #include <CurveCreator_ICurve.hxx>
 #include <CurveCreator_Utils.hxx>
 #include <HYDROGUI_CurveCreatorProfile.h>
+#include <HYDROData_Tool.h>
 #include <CurveCreator_Displayer.hxx>
 
 #include <OCCViewer_ViewPort3d.h>
 #include <QListWidget>
 #include <QPushButton>
 #include <SUIT_MessageBox.h>
+#include <QColorDialog>
 
 const QString splitter_key = "HYDROGUI_ProfileDlg::splitter";
 
 HYDROGUI_ProfileDlg::HYDROGUI_ProfileDlg( HYDROGUI_Module* theModule, const QString& theTitle, 
   bool theIsEdit )
-: HYDROGUI_ViewerDlg( theModule, theTitle, true ),
+: HYDROGUI_ViewerDlg( theModule, theTitle, true, false ),
   myName( NULL ), myProfileNames (NULL), myProfilesPointer (NULL),
   myIsEdit (theIsEdit)
 {
@@ -77,17 +79,26 @@ HYDROGUI_ProfileDlg::HYDROGUI_ProfileDlg( HYDROGUI_Module* theModule, const QStr
     myProfileNames = new QListWidget(this);
     myProfileNames->setSelectionMode(QAbstractItemView::SingleSelection);
     name_layout->addWidget(myProfileNames);
+
+    QVBoxLayout* btn_layout = new QVBoxLayout( name_frame );
+    btn_layout->setAlignment(Qt::AlignTop);
+
     myAddProfBtn = new QPushButton(tr("ADD_PROFILES"), this);    
     myRemProfBtn = new QPushButton(tr("REMOVE_PROFILE"), this);
-    name_layout->addWidget(myAddProfBtn);
-    name_layout->addWidget(myRemProfBtn);
+    mySetColorProfBtn = new QPushButton(tr("SETCOLOR_PROFILE"), this);
+    btn_layout->addWidget(myAddProfBtn);
+    btn_layout->addWidget(myRemProfBtn);
+    btn_layout->addWidget(mySetColorProfBtn);
+
+    name_layout->addLayout(btn_layout);
+
   }
 
   insertWidget( name_frame, 0, 0 );
 
   int anActionFlags = 
     CurveCreator_Widget::DisableNewSection | CurveCreator_Widget::DisableDetectionMode |
-    CurveCreator_Widget::DisableClosedSection;
+    CurveCreator_Widget::DisableClosedSection | CurveCreator_Widget::DisableSetColor;
   QStringList aCoordTitles;
   aCoordTitles << tr( "U_TITLE" ) << tr( "Z_TITLE" );
   myEditorWidget = new CurveCreator_Widget( this, NULL, anActionFlags, aCoordTitles );
@@ -112,6 +123,7 @@ HYDROGUI_ProfileDlg::HYDROGUI_ProfileDlg( HYDROGUI_Module* theModule, const QStr
     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)));
+    connect( mySetColorProfBtn, SIGNAL( clicked(bool)), this, SLOT( onSetColorBtnPressed(bool)));
   }
   myAddElementBox->hide();
 
@@ -142,6 +154,7 @@ void HYDROGUI_ProfileDlg::reset()
   myEditorWidget->reset();
   myEditorWidget->setActionMode( CurveCreator_Widget::AdditionMode );
   viewer()->setTrihedronShown( false ); // Issue #548
+  viewer()->setStaticTrihedronDisplayed(false);
   if (myProfileNames)
     myProfileNames->clear();
 }
@@ -330,6 +343,43 @@ void HYDROGUI_ProfileDlg::onRemoveBtnPressed(bool)
     emit RemoveProfile(theIndex);
 }
 
+void HYDROGUI_ProfileDlg::onSetColorBtnPressed(bool)
+{
+  int theIndex = GetProfileSelectionIndex();
+  if (theIndex < 0)
+    return;
+
+  HYDROGUI_CurveCreatorProfile* aCurve = (*myProfilesPointer)[theIndex];
+  
+  QColor aCurrentColor = HYDROData_Tool::toQtColor(/*aCurve->myCurveColor*/aCurve->getColorSection(0));
+  QColor newQCurCol = QColorDialog::getColor( aCurrentColor, this );
+  if( !newQCurCol.isValid() )
+    return;
+
+  Quantity_Color newOCCCol = HYDROData_Tool::toOccColor(newQCurCol);
+  aCurve->setColorSectionInternal(0, newOCCCol);
+  Handle(AIS_InteractiveObject) anAISObject = aCurve->getAISObject();
+  if (anAISObject)
+  {
+    //color points of shape in the same color as edges
+    Handle(Prs3d_PointAspect) anAspect = anAISObject->Attributes()->PointAspect();
+    anAspect->SetColor(newOCCCol);
+    anAISObject->Attributes()->SetPointAspect( anAspect );
+  }
+
+  QListWidgetItem* item = myProfileNames->item(theIndex);
+  QPixmap SPixmap(16, 16);
+  SPixmap.fill(newQCurCol);
+  QIcon SIcon(SPixmap);
+  item->setIcon( SIcon );
+
+  if( myProfilesPointer && 
+    myProfilesPointer->size()>0 && 
+    myProfilesPointer->at(0) && 
+    myProfilesPointer->at(0)->getDisplayer() )
+    myProfilesPointer->at(0)->getDisplayer()->Update();
+}
+
 void HYDROGUI_ProfileDlg::onProfileNameChanged(QListWidgetItem* item)
 {
   int ind = GetProfileSelectionIndex();