From b8a6578b8a09ecae38f85d1cd508253c216e5963 Mon Sep 17 00:00:00 2001 From: adv Date: Fri, 17 Jan 2014 06:12:18 +0000 Subject: [PATCH] Set color for object. --- src/HYDROData/HYDROData_Entity.cxx | 18 ++++++++++++++++- src/HYDROData/HYDROData_Entity.h | 7 ++++++- src/HYDROData/HYDROData_ImmersibleZone.cxx | 16 ++------------- src/HYDROData/HYDROData_Object.cxx | 23 ++++++++++++++++++++++ src/HYDROData/HYDROData_Object.h | 7 +++++++ src/HYDROData/HYDROData_PolylineXY.cxx | 12 +++++++++++ 6 files changed, 67 insertions(+), 16 deletions(-) diff --git a/src/HYDROData/HYDROData_Entity.cxx b/src/HYDROData/HYDROData_Entity.cxx index 797973ea..af16992f 100644 --- a/src/HYDROData/HYDROData_Entity.cxx +++ b/src/HYDROData/HYDROData_Entity.cxx @@ -527,9 +527,25 @@ void HYDROData_Entity::setPythonReferenceObject( MapOfTreatedObjects& if ( anIsToSetObject ) { + QString anObjName = GetObjPyName(); theScript << QString( "%1.%2( %3 );" ) - .arg( GetObjPyName() ).arg( theMethod ).arg( aRefObjName ); + .arg( anObjName ).arg( theMethod ).arg( aRefObjName ); } } +void HYDROData_Entity::setPythonObjectColor( QStringList& theScript, + const QColor& theColor, + const QColor& theDefaultColor, + const QString& theMethod ) const +{ + if ( theColor == theDefaultColor ) + return; //Do not set the color for object if it like default + + QString anObjName = GetObjPyName(); + theScript << QString( "%1.%2( QColor( %3, %4, %5, %6 ) );" ) + .arg( anObjName ).arg( theMethod ) + .arg( theColor.red() ).arg( theColor.green() ) + .arg( theColor.blue() ).arg( theColor.alpha() ); +} + diff --git a/src/HYDROData/HYDROData_Entity.h b/src/HYDROData/HYDROData_Entity.h index b1b36333..0f48dbbc 100644 --- a/src/HYDROData/HYDROData_Entity.h +++ b/src/HYDROData/HYDROData_Entity.h @@ -333,12 +333,17 @@ protected: const Handle(HYDROData_Entity)& theRefObject, const QString& theMethod ) const; + void setPythonObjectColor( QStringList& theScript, + const QColor& theColor, + const QColor& theDefaultColor, + const QString& theMethod ) const; + /** * Dump the initial object creation to a Python script. * You should call it from DumpToPython implementation before * dumping fields of the object. */ - QStringList dumpObjectCreation( MapOfTreatedObjects& theTreatedObjects ) const; + HYDRODATA_EXPORT virtual QStringList dumpObjectCreation( MapOfTreatedObjects& theTreatedObjects ) const; /** * Returns an object type name as a string for dumping to Python. diff --git a/src/HYDROData/HYDROData_ImmersibleZone.cxx b/src/HYDROData/HYDROData_ImmersibleZone.cxx index 3232ae96..d8673dae 100644 --- a/src/HYDROData/HYDROData_ImmersibleZone.cxx +++ b/src/HYDROData/HYDROData_ImmersibleZone.cxx @@ -43,22 +43,9 @@ HYDROData_ImmersibleZone::~HYDROData_ImmersibleZone() QStringList HYDROData_ImmersibleZone::DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const { QStringList aResList = dumpObjectCreation( theTreatedObjects ); + QString aZoneName = GetObjPyName(); - QColor aFillingColor = GetFillingColor(); - aResList << QString( "filling_color = QColor( %1, %2, %3, %4 );" ) - .arg( aFillingColor.red() ).arg( aFillingColor.green() ) - .arg( aFillingColor.blue() ).arg( aFillingColor.alpha() ); - aResList << QString( "%1.SetFillingColor( filling_color );" ).arg( aZoneName ); - aResList << QString( "" ); - - QColor aBorderColor = GetBorderColor(); - aResList << QString( "border_color = QColor( %1, %2, %3, %4 );" ) - .arg( aBorderColor.red() ).arg( aBorderColor.green() ) - .arg( aBorderColor.blue() ).arg( aBorderColor.alpha() ); - aResList << QString( "%1.SetBorderColor( border_color );" ).arg( aZoneName ); - aResList << QString( "" ); - Handle(HYDROData_IAltitudeObject) aRefAltitude = GetAltitudeObject(); setPythonReferenceObject( theTreatedObjects, aResList, aRefAltitude, "SetAltitudeObject" ); @@ -66,6 +53,7 @@ QStringList HYDROData_ImmersibleZone::DumpToPython( MapOfTreatedObjects& theTrea setPythonReferenceObject( theTreatedObjects, aResList, aRefPolyline, "SetPolyline" ); aResList << QString( "" ); + aResList << QString( "%1.Update();" ).arg( aZoneName ); aResList << QString( "" ); diff --git a/src/HYDROData/HYDROData_Object.cxx b/src/HYDROData/HYDROData_Object.cxx index e018ca24..7204f97f 100644 --- a/src/HYDROData/HYDROData_Object.cxx +++ b/src/HYDROData/HYDROData_Object.cxx @@ -230,6 +230,29 @@ QColor HYDROData_Object::getDefaultBorderColor() const return QColor( Qt::transparent ); } +QStringList HYDROData_Object::dumpObjectCreation( MapOfTreatedObjects& theTreatedObjects ) const +{ + QStringList aResList = HYDROData_Entity::dumpObjectCreation( theTreatedObjects ); + if ( aResList.isEmpty() ) + return aResList; //Object was not created + + QStringList aColorsDef; + + QColor aFillingColor = GetFillingColor(); + setPythonObjectColor( aColorsDef, aFillingColor, getDefaultFillingColor(), "SetFillingColor" ); + + QColor aBorderColor = GetBorderColor(); + setPythonObjectColor( aColorsDef, aBorderColor, getDefaultBorderColor(), "SetBorderColor" ); + + if ( !aColorsDef.isEmpty() ) + { + aResList << aColorsDef; + aResList << QString( "" ); + } + + return aResList; +} + ObjectKind HYDROData_Object::getAltitudeObjectType() const { return KIND_UNKNOWN; diff --git a/src/HYDROData/HYDROData_Object.h b/src/HYDROData/HYDROData_Object.h index d59e4708..302f5580 100644 --- a/src/HYDROData/HYDROData_Object.h +++ b/src/HYDROData/HYDROData_Object.h @@ -168,6 +168,13 @@ protected: protected: + /** + * Dump the initial object creation to a Python script. + * Reimplemented to dump the object colors. + */ + HYDRODATA_EXPORT virtual QStringList dumpObjectCreation( MapOfTreatedObjects& theTreatedObjects ) const; + + /** * Checks and if necessary create child 3D object. * Reimplement this function in your subclass if you diff --git a/src/HYDROData/HYDROData_PolylineXY.cxx b/src/HYDROData/HYDROData_PolylineXY.cxx index d418144a..cdbc3752 100755 --- a/src/HYDROData/HYDROData_PolylineXY.cxx +++ b/src/HYDROData/HYDROData_PolylineXY.cxx @@ -109,6 +109,18 @@ QStringList HYDROData_PolylineXY::DumpToPython( MapOfTreatedObjects& theTreatedO QStringList aResList = dumpObjectCreation( theTreatedObjects ); QString aPolylineName = GetObjPyName(); + // Set the wire color + QStringList aWireColorDef; + + QColor aWireColor = GetWireColor(); + setPythonObjectColor( aWireColorDef, aWireColor, DefaultWireColor(), "SetWireColor" ); + + if ( !aWireColorDef.isEmpty() ) + { + aResList << aWireColorDef; + aResList << QString( "" ); + } + // Set polilyne data NCollection_Sequence aSectNames; NCollection_Sequence aSectTypes; -- 2.39.2