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>
29 #include <HYDROData_LandCover.h>
31 #include <LightApp_Application.h>
32 #include <LightApp_UpdateFlags.h>
34 #include <SUIT_Desktop.h>
36 HYDROGUI_SetColorOp::HYDROGUI_SetColorOp( HYDROGUI_Module* theModule )
37 : HYDROGUI_Operation( theModule ),
40 setName( tr( "SET_COLOR" ) );
43 HYDROGUI_SetColorOp::~HYDROGUI_SetColorOp()
47 bool HYDROGUI_SetColorOp::CanObjectBeColored( const Handle(HYDROData_Entity)& theObject )
49 if ( theObject.IsNull() )
52 return theObject->IsKind( STANDARD_TYPE(HYDROData_Object) ) ||
53 theObject->IsKind( STANDARD_TYPE(HYDROData_IPolyline) ) ||
54 theObject->IsKind( STANDARD_TYPE(HYDROData_LandCover) );
57 void HYDROGUI_SetColorOp::startOperation()
59 HYDROGUI_Operation::startOperation();
61 // Get the selected object
62 //myEditedObject = Handle(HYDROData_Object)::DownCast( HYDROGUI_Tool::GetSelectedObject( module() ) );
63 myEditedObject = HYDROGUI_Tool::GetSelectedObject( module() );
64 if ( !CanObjectBeColored( myEditedObject ) )
70 bool anIsOneColor = false;
72 // Get colors from the object
73 QColor aFirstColor, aSecondColor;
74 if ( myEditedObject->IsKind( STANDARD_TYPE(HYDROData_Object) ) )
76 Handle(HYDROData_Object) aGeomObject =
77 Handle(HYDROData_Object)::DownCast( myEditedObject );
79 if ( myEditedObject->GetKind() == KIND_POLYLINE ||
80 myEditedObject->GetKind() == KIND_PROFILE )
82 aFirstColor = aGeomObject->GetBorderColor();
87 aFirstColor = aGeomObject->GetFillingColor();
88 aSecondColor = aGeomObject->GetBorderColor();
91 else if ( myEditedObject->IsKind( STANDARD_TYPE(HYDROData_IPolyline) ) )
93 Handle(HYDROData_IPolyline) aPolyObject =
94 Handle(HYDROData_IPolyline)::DownCast( myEditedObject );
96 aFirstColor = aPolyObject->GetWireColor();
100 else if ( myEditedObject->IsKind( STANDARD_TYPE(HYDROData_LandCover) ) )
102 Handle(HYDROData_LandCover) aLandCover =
103 Handle(HYDROData_LandCover)::DownCast( myEditedObject );
105 aFirstColor = aLandCover->GetFillingColor();
106 aSecondColor = aLandCover->GetBorderColor();
109 // Create color dialog
110 myColorDlg = new HYDROGUI_ColorDlg( module()->getApp()->desktop(), anIsOneColor );
111 myColorDlg->setModal( true );
112 myColorDlg->setWindowTitle( getName() );
114 // Set colors from the object
115 myColorDlg->setFirstColor( aFirstColor );
116 myColorDlg->setSecondColor( aSecondColor );
118 // Connect the dialog to operation slots
119 connect( myColorDlg, SIGNAL( accepted() ), this, SLOT( onApply() ) );
120 connect( myColorDlg, SIGNAL( rejected() ), this, SLOT( onCancel() ) );
126 bool HYDROGUI_SetColorOp::processApply( int& theUpdateFlags,
127 QString& theErrorMsg,
128 QStringList& theBrowseObjectsEntries )
130 if ( !myColorDlg || myEditedObject.IsNull() )
133 QColor aFirstColor = myColorDlg->getFirstColor();
134 QColor aSecondColor = myColorDlg->getSecondColor();
136 if ( myEditedObject->IsKind( STANDARD_TYPE(HYDROData_Object) ) )
138 Handle(HYDROData_Object) aGeomObject =
139 Handle(HYDROData_Object)::DownCast( myEditedObject );
141 if ( myEditedObject->GetKind() == KIND_POLYLINE ||
142 myEditedObject->GetKind() == KIND_PROFILE )
144 aGeomObject->SetBorderColor( aFirstColor );
148 aGeomObject->SetFillingColor( aFirstColor );
149 aGeomObject->SetBorderColor( aSecondColor );
152 else if ( myEditedObject->IsKind( STANDARD_TYPE(HYDROData_IPolyline) ) )
154 Handle(HYDROData_IPolyline) aPolyObject =
155 Handle(HYDROData_IPolyline)::DownCast( myEditedObject );
157 aPolyObject->SetWireColor( aFirstColor );
159 else if ( myEditedObject->IsKind( STANDARD_TYPE(HYDROData_LandCover) ) )
161 Handle(HYDROData_LandCover) aLandCover =
162 Handle(HYDROData_LandCover)::DownCast( myEditedObject );
164 aLandCover->SetFillingColor( aFirstColor );
165 aLandCover->SetBorderColor( aSecondColor );
168 module()->setIsToUpdate( myEditedObject );
170 theUpdateFlags = UF_Model | UF_OCCViewer | UF_OCC_Forced | UF_VTKViewer;