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 "HYDROData_Object.h"
21 #include "HYDROData_DummyObject3D.h"
22 #include "HYDROData_ShapesGroup.h"
23 #include "HYDROData_Tool.h"
24 #include "HYDROData_Iterator.h"
25 #include "HYDROData_IAltitudeObject.h"
27 #include <TNaming_Builder.hxx>
28 #include <TNaming_NamedShape.hxx>
30 #include <TopoDS_Shape.hxx>
34 IMPLEMENT_STANDARD_HANDLE(HYDROData_Object,HYDROData_Entity)
35 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Object,HYDROData_Entity)
37 HYDROData_Object::HYDROData_Object()
42 HYDROData_Object::~HYDROData_Object()
46 void HYDROData_Object::SetName( const QString& theName )
48 QString anOldObjName = GetName();
49 if ( anOldObjName != theName )
51 HYDROData_SequenceOfObjects aGroups = GetGroups();
52 HYDROData_SequenceOfObjects::Iterator anIter( aGroups );
53 for ( ; anIter.More(); anIter.Next() )
55 Handle(HYDROData_ShapesGroup) aGroup =
56 Handle(HYDROData_ShapesGroup)::DownCast( anIter.Value() );
57 if ( aGroup.IsNull() )
60 HYDROData_Tool::UpdateChildObjectName( anOldObjName, theName, aGroup );
63 Handle(HYDROData_DummyObject3D) anObject3D = GetObject3D();
64 if ( !anObject3D.IsNull() )
65 HYDROData_Tool::UpdateChildObjectName( anOldObjName, theName, anObject3D );
67 Handle(HYDROData_IAltitudeObject) anAltitudeObj = getChildAltitudeObject();
68 if ( !anAltitudeObj.IsNull() )
69 HYDROData_Tool::UpdateChildObjectName( anOldObjName, theName, anAltitudeObj );
72 HYDROData_Entity::SetName( theName );
75 void HYDROData_Object::Update()
80 checkAndSetAltitudeObject();
81 HYDROData_Entity::Update();
84 HYDROData_SequenceOfObjects HYDROData_Object::GetAllReferenceObjects() const
86 HYDROData_SequenceOfObjects aResSeq = HYDROData_Entity::GetAllReferenceObjects();
88 Handle(HYDROData_IAltitudeObject) aRefAltitude = GetAltitudeObject();
89 if ( !aRefAltitude.IsNull() )
90 aResSeq.Append( aRefAltitude );
95 void HYDROData_Object::SetToUpdate( bool theFlag )
97 HYDROData_Entity::SetToUpdate( theFlag );
99 Handle(HYDROData_DummyObject3D) anObject3D = GetObject3D();
100 if ( !anObject3D.IsNull() )
101 anObject3D->SetToUpdate( theFlag );
104 void HYDROData_Object::SetTopShape( const TopoDS_Shape& theShape )
106 TNaming_Builder aBuilder( myLab.FindChild( DataTag_TopShape ) );
107 aBuilder.Generated( theShape );
110 void HYDROData_Object::SetShape3D( const TopoDS_Shape& theShape )
112 TNaming_Builder aBuilder( myLab.FindChild( DataTag_Shape3D ) );
113 aBuilder.Generated( theShape );
115 // Check the object 3D existance
116 checkAndSetObject3D();
119 Handle(HYDROData_DummyObject3D) HYDROData_Object::GetObject3D() const
121 Handle(HYDROData_DummyObject3D) anObject;
123 TDF_Label aLabel = myLab.FindChild( DataTag_Object3D, false );
124 if ( !aLabel.IsNull() )
126 TDF_Label aChildLabel = aLabel.FindChild( 0, false );
127 if ( !aChildLabel.IsNull() )
129 anObject = Handle(HYDROData_DummyObject3D)::DownCast(
130 HYDROData_Iterator::Object( aChildLabel ) );
137 void HYDROData_Object::checkAndSetObject3D()
139 TDF_Label aLabel = myLab.FindChild( DataTag_Object3D, false );
140 if ( !aLabel.IsNull() )
143 TDF_Label aChildLabel = myLab.FindChild( DataTag_Object3D ).FindChild( 0 );
144 HYDROData_Iterator::CreateObject( aChildLabel, KIND_DUMMY_3D );
147 HYDROData_SequenceOfObjects HYDROData_Object::GetGroups() const
149 return GetReferenceObjects( DataTag_EdgesGroup );
152 Handle(HYDROData_ShapesGroup) HYDROData_Object::GetGroup( const int theGroupId ) const
154 Handle(HYDROData_ShapesGroup) aResGroup;
156 HYDROData_SequenceOfObjects aGroups = GetGroups();
157 if ( theGroupId < 0 || theGroupId >= aGroups.Length() )
160 aResGroup = Handle(HYDROData_ShapesGroup)::DownCast( aGroups.Value( theGroupId + 1 ) );
165 int HYDROData_Object::GetGroupId( const Handle(HYDROData_ShapesGroup)& theGroup ) const
169 HYDROData_SequenceOfObjects aGroups = GetGroups();
170 for ( int i = 1, n = aGroups.Length(); i <= n; ++i )
172 Handle(HYDROData_ShapesGroup) aGroup =
173 Handle(HYDROData_ShapesGroup)::DownCast( aGroups.Value( i ) );
174 if ( IsEqual( theGroup, aGroup ) )
184 bool HYDROData_Object::SetAltitudeObject(
185 const Handle(HYDROData_IAltitudeObject)& theAltitude )
187 if ( theAltitude.IsNull() )
190 Handle(HYDROData_IAltitudeObject) aPrevAltitude = GetAltitudeObject();
191 if ( IsEqual( aPrevAltitude, theAltitude ) )
194 SetReferenceObject( theAltitude, DataTag_AltitudeObject );
196 // Indicate model of the need to update object
202 Handle(HYDROData_IAltitudeObject) HYDROData_Object::GetAltitudeObject() const
204 return Handle(HYDROData_IAltitudeObject)::DownCast(
205 GetReferenceObject( DataTag_AltitudeObject ) );
208 void HYDROData_Object::RemoveAltitudeObject()
210 Handle(HYDROData_IAltitudeObject) aPrevAltitude = GetAltitudeObject();
211 if ( aPrevAltitude.IsNull() )
214 ClearReferenceObjects( DataTag_AltitudeObject );
216 // Indicate model of the need to update object
220 void HYDROData_Object::SetFillingColor( const QColor& theColor )
222 SetColor( theColor, DataTag_FillingColor );
225 QColor HYDROData_Object::GetFillingColor() const
227 return GetColor( getDefaultFillingColor(), DataTag_FillingColor );
230 void HYDROData_Object::SetBorderColor( const QColor& theColor )
232 SetColor( theColor, DataTag_BorderColor );
235 QColor HYDROData_Object::GetBorderColor() const
237 return GetColor( getDefaultBorderColor(), DataTag_BorderColor );
240 QColor HYDROData_Object::getDefaultFillingColor() const
242 return QColor( Qt::yellow );
245 QColor HYDROData_Object::getDefaultBorderColor() const
247 return QColor( Qt::transparent );
250 QStringList HYDROData_Object::dumpObjectCreation( MapOfTreatedObjects& theTreatedObjects ) const
252 QStringList aResList = HYDROData_Entity::dumpObjectCreation( theTreatedObjects );
253 if ( aResList.isEmpty() )
254 return aResList; //Object was not created
256 QStringList aColorsDef;
258 QColor aFillingColor = GetFillingColor();
259 setPythonObjectColor( aColorsDef, aFillingColor, getDefaultFillingColor(), "SetFillingColor" );
261 QColor aBorderColor = GetBorderColor();
262 setPythonObjectColor( aColorsDef, aBorderColor, getDefaultBorderColor(), "SetBorderColor" );
264 if ( !aColorsDef.isEmpty() )
266 aResList << aColorsDef;
267 aResList << QString( "" );
273 ObjectKind HYDROData_Object::getAltitudeObjectType() const
278 Handle(HYDROData_IAltitudeObject) HYDROData_Object::getChildAltitudeObject() const
280 Handle(HYDROData_IAltitudeObject) anObject;
282 TDF_Label aLabel = myLab.FindChild( DataTag_ChildAltitudeObject, false );
283 if ( !aLabel.IsNull() )
285 TDF_Label aChildLabel = aLabel.FindChild( 0, false );
286 if ( !aChildLabel.IsNull() )
288 anObject = Handle(HYDROData_IAltitudeObject)::DownCast(
289 HYDROData_Iterator::Object( aChildLabel ) );
296 void HYDROData_Object::checkAndSetAltitudeObject()
298 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
300 ObjectKind anAltitudeObjectType = getAltitudeObjectType();
301 if ( anAltitudeObjectType == KIND_UNKNOWN )
302 return; // No need to create altitude object
304 TDF_Label aLabel = myLab.FindChild( DataTag_ChildAltitudeObject, false );
305 if ( !aLabel.IsNull() )
308 TDF_Label aChildLabel = myLab.FindChild( DataTag_ChildAltitudeObject ).FindChild( 0 );
310 Handle(HYDROData_IAltitudeObject) anAltitudeObject =
311 Handle(HYDROData_IAltitudeObject)::DownCast(
312 HYDROData_Iterator::CreateObject( aChildLabel, anAltitudeObjectType ) );
314 QString anAltitudePref = GetName() + "_Altitude";
315 QString anAltitudeName = HYDROData_Tool::GenerateObjectName( aDocument, anAltitudePref );
316 anAltitudeObject->SetName( anAltitudeName );
318 SetAltitudeObject( anAltitudeObject );
321 Handle(HYDROData_ShapesGroup) HYDROData_Object::createGroupObject()
323 TDF_Label aNewLab = myLab.FindChild( DataTag_EdgesGroup ).NewChild();
325 Handle(HYDROData_ShapesGroup) aNewGroup =
326 Handle(HYDROData_ShapesGroup)::DownCast( HYDROData_Iterator::CreateObject( aNewLab, KIND_SHAPES_GROUP ) );
327 AddReferenceObject( aNewGroup, DataTag_EdgesGroup );
332 void HYDROData_Object::removeGroupObjects()
334 TDF_Label aLabel = myLab.FindChild( DataTag_EdgesGroup, false );
335 if ( !aLabel.IsNull() )
336 aLabel.ForgetAllAttributes();
339 TopoDS_Shape HYDROData_Object::getTopShape() const
341 TDF_Label aLabel = myLab.FindChild( DataTag_TopShape, false );
342 if ( !aLabel.IsNull() )
344 Handle(TNaming_NamedShape) aNamedShape;
345 if( aLabel.FindAttribute( TNaming_NamedShape::GetID(), aNamedShape ) )
346 return aNamedShape->Get();
349 return TopoDS_Shape();
352 void HYDROData_Object::removeTopShape()
354 TDF_Label aLabel = myLab.FindChild( DataTag_TopShape, false );
355 if ( !aLabel.IsNull() )
356 aLabel.ForgetAllAttributes();
359 TopoDS_Shape HYDROData_Object::getShape3D() const
361 TDF_Label aLabel = myLab.FindChild( DataTag_Shape3D, false );
362 if ( !aLabel.IsNull() )
364 Handle(TNaming_NamedShape) aNamedShape;
365 if( aLabel.FindAttribute( TNaming_NamedShape::GetID(), aNamedShape ) )
366 return aNamedShape->Get();
369 return TopoDS_Shape();
372 void HYDROData_Object::removeShape3D()
374 TDF_Label aLabel = myLab.FindChild( DataTag_Shape3D, false );
375 if ( !aLabel.IsNull() )
376 aLabel.ForgetAllAttributes();