1 // Copyright (C) 2014-2015 EDF-R&D
2 // This library is free software; you can redistribute it and/or
3 // modify it under the terms of the GNU Lesser General Public
4 // License as published by the Free Software Foundation; either
5 // version 2.1 of the License, or (at your option) any later version.
7 // This library is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 // Lesser General Public License for more details.
12 // You should have received a copy of the GNU Lesser General Public
13 // License along with this library; if not, write to the Free Software
14 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #include "HYDROGUI_SetColorOp.h"
21 #include "HYDROGUI_ColorDlg.h"
22 #include "HYDROGUI_DataModel.h"
23 #include "HYDROGUI_Module.h"
24 #include "HYDROGUI_Tool.h"
25 #include "HYDROGUI_UpdateFlags.h"
27 #include <HYDROData_Object.h>
28 #include <HYDROData_IPolyline.h>
30 #include <LightApp_Application.h>
31 #include <LightApp_UpdateFlags.h>
33 #include <SUIT_Desktop.h>
35 HYDROGUI_SetColorOp::HYDROGUI_SetColorOp( HYDROGUI_Module* theModule )
36 : HYDROGUI_Operation( theModule ),
39 setName( tr( "SET_COLOR" ) );
42 HYDROGUI_SetColorOp::~HYDROGUI_SetColorOp()
46 bool HYDROGUI_SetColorOp::CanObjectBeColored( const Handle(HYDROData_Entity)& theObject )
48 if ( theObject.IsNull() )
51 return theObject->IsKind( STANDARD_TYPE(HYDROData_Object) ) ||
52 theObject->IsKind( STANDARD_TYPE(HYDROData_IPolyline) );
55 void HYDROGUI_SetColorOp::startOperation()
57 HYDROGUI_Operation::startOperation();
59 // Get the selected object
60 //myEditedObject = Handle(HYDROData_Object)::DownCast( HYDROGUI_Tool::GetSelectedObject( module() ) );
61 myEditedObject = HYDROGUI_Tool::GetSelectedObject( module() );
62 if ( !CanObjectBeColored( myEditedObject ) )
68 bool anIsOneColor = false;
70 // Get colors from the object
71 QColor aFirstColor, aSecondColor;
72 if ( myEditedObject->IsKind( STANDARD_TYPE(HYDROData_Object) ) )
74 Handle(HYDROData_Object) aGeomObject =
75 Handle(HYDROData_Object)::DownCast( myEditedObject );
77 if ( myEditedObject->GetKind() == KIND_POLYLINE ||
78 myEditedObject->GetKind() == KIND_PROFILE )
80 aFirstColor = aGeomObject->GetBorderColor();
85 aFirstColor = aGeomObject->GetFillingColor();
86 aSecondColor = aGeomObject->GetBorderColor();
89 else if ( myEditedObject->IsKind( STANDARD_TYPE(HYDROData_IPolyline) ) )
91 Handle(HYDROData_IPolyline) aPolyObject =
92 Handle(HYDROData_IPolyline)::DownCast( myEditedObject );
94 aFirstColor = aPolyObject->GetWireColor();
99 // Create color dialog
100 myColorDlg = new HYDROGUI_ColorDlg( module()->getApp()->desktop(), anIsOneColor );
101 myColorDlg->setModal( true );
102 myColorDlg->setWindowTitle( getName() );
104 // Set colors from the object
105 myColorDlg->setFirstColor( aFirstColor );
106 myColorDlg->setSecondColor( aSecondColor );
108 // Connect the dialog to operation slots
109 connect( myColorDlg, SIGNAL( accepted() ), this, SLOT( onApply() ) );
110 connect( myColorDlg, SIGNAL( rejected() ), this, SLOT( onCancel() ) );
116 bool HYDROGUI_SetColorOp::processApply( int& theUpdateFlags,
117 QString& theErrorMsg,
118 QStringList& theBrowseObjectsEntries )
120 if ( !myColorDlg || myEditedObject.IsNull() )
123 QColor aFirstColor = myColorDlg->getFirstColor();
124 QColor aSecondColor = myColorDlg->getSecondColor();
126 if ( myEditedObject->IsKind( STANDARD_TYPE(HYDROData_Object) ) )
128 Handle(HYDROData_Object) aGeomObject =
129 Handle(HYDROData_Object)::DownCast( myEditedObject );
131 if ( myEditedObject->GetKind() == KIND_POLYLINE ||
132 myEditedObject->GetKind() == KIND_PROFILE )
134 aGeomObject->SetBorderColor( aFirstColor );
138 aGeomObject->SetFillingColor( aFirstColor );
139 aGeomObject->SetBorderColor( aSecondColor );
142 else if ( myEditedObject->IsKind( STANDARD_TYPE(HYDROData_IPolyline) ) )
144 Handle(HYDROData_IPolyline) aPolyObject =
145 Handle(HYDROData_IPolyline)::DownCast( myEditedObject );
147 aPolyObject->SetWireColor( aFirstColor );
150 module()->setIsToUpdate( myEditedObject );
152 theUpdateFlags = UF_Model | UF_OCCViewer | UF_OCC_Forced | UF_VTKViewer;