-// Copyright (C) 2007-2013 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
-//
+// Copyright (C) 2014-2015 EDF-R&D
// 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
#include "HYDROGUI_Tool.h"
#include "HYDROGUI_UpdateFlags.h"
+#include <HYDROData_Object.h>
+#include <HYDROData_IPolyline.h>
+#include <HYDROData_LandCover.h>
+
#include <LightApp_Application.h>
#include <LightApp_UpdateFlags.h>
{
}
+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) ) ||
+ theObject->IsKind( STANDARD_TYPE(HYDROData_LandCover) );
+}
+
void HYDROGUI_SetColorOp::startOperation()
{
HYDROGUI_Operation::startOperation();
// Get the selected object
- myEditedObject = Handle(HYDROData_Object)::DownCast( HYDROGUI_Tool::GetSelectedObject( module() ) );
-
- if( !myEditedObject.IsNull() ) {
- // Get colors from the object
- QColor aFillingColor = myEditedObject->GetFillingColor();
- QColor aBorderColor = myEditedObject->GetBorderColor();
+ //myEditedObject = Handle(HYDROData_Object)::DownCast( HYDROGUI_Tool::GetSelectedObject( module() ) );
+ myEditedObject = HYDROGUI_Tool::GetSelectedObject( module() );
+ if ( !CanObjectBeColored( myEditedObject ) )
+ {
+ abort();
+ return;
+ }
- // Create color dialog
- myColorDlg = new HYDROGUI_ColorDlg( module()->getApp()->desktop() );
- myColorDlg->setModal( true );
- myColorDlg->setWindowTitle( getName() );
+ 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 );
- // Set colors from the object
- myColorDlg->setFillingColor( aFillingColor );
- myColorDlg->setBorderColor( aBorderColor );
+ aFirstColor = aPolyObject->GetWireColor();
- // Connect the dialog to operation slots
- connect( myColorDlg, SIGNAL( accepted() ), this, SLOT( onApply() ) );
- connect( myColorDlg, SIGNAL( rejected() ), this, SLOT( onCancel() ) );
+ anIsOneColor = true;
+ }
+ else if ( myEditedObject->IsKind( STANDARD_TYPE(HYDROData_LandCover) ) )
+ {
+ Handle(HYDROData_LandCover) aLandCover =
+ Handle(HYDROData_LandCover)::DownCast( myEditedObject );
- // Show the dialog
- myColorDlg->exec();
+ aFirstColor = aLandCover->GetFillingColor();
+ aSecondColor = aLandCover->GetBorderColor();
}
+
+ // Create color dialog
+ myColorDlg = new HYDROGUI_ColorDlg( module()->getApp()->desktop(), anIsOneColor );
+ myColorDlg->setModal( true );
+ myColorDlg->setWindowTitle( getName() );
+
+ // 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.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 );
- if ( myColorDlg && myEditedObject ) {
- QColor aFillingColor = myColorDlg->getFillingColor();
- QColor aBorderColor = myColorDlg->getBorderColor();
+ aPolyObject->SetWireColor( aFirstColor );
+ }
+ else if ( myEditedObject->IsKind( STANDARD_TYPE(HYDROData_LandCover) ) )
+ {
+ Handle(HYDROData_LandCover) aLandCover =
+ Handle(HYDROData_LandCover)::DownCast( myEditedObject );
- myEditedObject->SetFillingColor( aFillingColor );
- myEditedObject->SetBorderColor( aBorderColor );
+ aLandCover->SetFillingColor( aFirstColor );
+ aLandCover->SetBorderColor( aSecondColor );
+ }
- 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;
}