Salome HOME
Fit All after was added stream selection and displaying in embedded viewer.
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_SetColorOp.cxx
index 245e11c66425b39a9f7942799f8841b23cb5d7f7..f09f4d2add71ff666914ee12a5e3ada00e21c25b 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2015  CEA/DEN, EDF R&D, OPEN CASCADE
 //
 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
@@ -6,7 +6,7 @@
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 // License as published by the Free Software Foundation; either
-// version 2.1 of the License.
+// version 2.1 of the License, or (at your option) any later version.
 //
 // This library is distributed in the hope that it will be useful,
 // but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -28,6 +28,9 @@
 #include "HYDROGUI_Tool.h"
 #include "HYDROGUI_UpdateFlags.h"
 
+#include <HYDROData_Object.h>
+#include <HYDROData_IPolyline.h>
+
 #include <LightApp_Application.h>
 #include <LightApp_UpdateFlags.h>
 
@@ -44,52 +47,113 @@ HYDROGUI_SetColorOp::~HYDROGUI_SetColorOp()
 {
 }
 
+bool HYDROGUI_SetColorOp::CanObjectBeColored( const Handle(HYDROData_Entity)& theObject )
+{
+  if ( theObject.IsNull() )
+    return false;
+
+  return theObject->IsKind( STANDARD_TYPE(HYDROData_Object) ) ||
+         theObject->IsKind( STANDARD_TYPE(HYDROData_IPolyline) );
+}
+
 void HYDROGUI_SetColorOp::startOperation()
 {
   HYDROGUI_Operation::startOperation();
 
   // Get the selected object
-  myEditedObject = Handle(HYDROData_Object)::DownCast( HYDROGUI_Tool::GetSelectedObject( module() ) );
+  //myEditedObject = Handle(HYDROData_Object)::DownCast( HYDROGUI_Tool::GetSelectedObject( module() ) );
+  myEditedObject = HYDROGUI_Tool::GetSelectedObject( module() );
+  if ( !CanObjectBeColored( myEditedObject ) )
+  {
+    abort();
+    return;
+  }
 
-  if( !myEditedObject.IsNull() ) {
-    // Get colors from the object
-    QColor aFillingColor = myEditedObject->GetFillingColor();
-    QColor aBorderColor = myEditedObject->GetBorderColor();
+  bool anIsOneColor = false;
+
+  // Get colors from the object
+  QColor aFirstColor, aSecondColor;
+  if ( myEditedObject->IsKind( STANDARD_TYPE(HYDROData_Object) ) )
+  {
+    Handle(HYDROData_Object) aGeomObject =
+      Handle(HYDROData_Object)::DownCast( myEditedObject );
+
+    if ( myEditedObject->GetKind() == KIND_POLYLINE ||
+         myEditedObject->GetKind() == KIND_PROFILE )
+    {
+      aFirstColor = aGeomObject->GetBorderColor();
+      anIsOneColor = true;
+    }
+    else
+    {
+      aFirstColor = aGeomObject->GetFillingColor();
+      aSecondColor = aGeomObject->GetBorderColor();
+    }
+  }
+  else if ( myEditedObject->IsKind( STANDARD_TYPE(HYDROData_IPolyline) ) )
+  {
+    Handle(HYDROData_IPolyline) aPolyObject =
+      Handle(HYDROData_IPolyline)::DownCast( myEditedObject );
 
-    // Create color dialog
-    myColorDlg = new HYDROGUI_ColorDlg( module()->getApp()->desktop() );
-    myColorDlg->setModal( true );
-    myColorDlg->setWindowTitle( getName() );
+    aFirstColor = aPolyObject->GetWireColor();
 
-    // Set colors from the object
-    myColorDlg->setFillingColor( aFillingColor );
-    myColorDlg->setBorderColor( aBorderColor );
+    anIsOneColor = true;
+  }
 
-    // Connect the dialog to operation slots
-    connect( myColorDlg, SIGNAL( accepted() ), this, SLOT( onApply()  ) );
-    connect( myColorDlg, SIGNAL( rejected() ), this, SLOT( onCancel() ) );
+  // Create color dialog
+  myColorDlg = new HYDROGUI_ColorDlg( module()->getApp()->desktop(), anIsOneColor );
+  myColorDlg->setModal( true );
+  myColorDlg->setWindowTitle( getName() );
 
-    // Show the dialog
-    myColorDlg->exec();    
-  }
+  // Set colors from the object
+  myColorDlg->setFirstColor( aFirstColor );
+  myColorDlg->setSecondColor( aSecondColor );
+
+  // Connect the dialog to operation slots
+  connect( myColorDlg, SIGNAL( accepted() ), this, SLOT( onApply()  ) );
+  connect( myColorDlg, SIGNAL( rejected() ), this, SLOT( onCancel() ) );
+
+  // Show the dialog
+  myColorDlg->exec();
 }
 
 bool HYDROGUI_SetColorOp::processApply( int& theUpdateFlags,
-                                        QString& theErrorMsg )
+                                        QString& theErrorMsg,
+                                        QStringList& theBrowseObjectsEntries )
 {
-  bool anIsOk = false;
-
-  if ( myColorDlg && myEditedObject ) {
-    QColor aFillingColor = myColorDlg->getFillingColor();
-    QColor aBorderColor = myColorDlg->getBorderColor();
+  if ( !myColorDlg || myEditedObject.IsNull() )
+    return false;
+
+  QColor aFirstColor = myColorDlg->getFirstColor();
+  QColor aSecondColor = myColorDlg->getSecondColor();
+
+  if ( myEditedObject->IsKind( STANDARD_TYPE(HYDROData_Object) ) )
+  {
+    Handle(HYDROData_Object) aGeomObject =
+      Handle(HYDROData_Object)::DownCast( myEditedObject );
+
+    if ( myEditedObject->GetKind() == KIND_POLYLINE ||
+         myEditedObject->GetKind() == KIND_PROFILE  )
+    {
+      aGeomObject->SetBorderColor( aFirstColor );
+    }
+    else
+    {
+      aGeomObject->SetFillingColor( aFirstColor );
+      aGeomObject->SetBorderColor( aSecondColor );
+    }
+  }
+  else if ( myEditedObject->IsKind( STANDARD_TYPE(HYDROData_IPolyline) ) )
+  {
+    Handle(HYDROData_IPolyline) aPolyObject =
+      Handle(HYDROData_IPolyline)::DownCast( myEditedObject );
 
-    myEditedObject->SetFillingColor( aFillingColor );
-    myEditedObject->SetBorderColor( aBorderColor );
+    aPolyObject->SetWireColor( aFirstColor );
+  }
 
-    theUpdateFlags = UF_Model | UF_OCCViewer | UF_OCC_Forced;
+  module()->setIsToUpdate( myEditedObject );
 
-    anIsOk = true;
-  }
+  theUpdateFlags = UF_Model | UF_OCCViewer | UF_OCC_Forced | UF_VTKViewer;
   
-  return anIsOk;
+  return true;
 }