1 // Copyright (C) 2007-2015 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #include "HYDROData_Object.h"
25 #include "HYDROData_DummyObject3D.h"
26 #include "HYDROData_ShapesGroup.h"
27 #include "HYDROData_Tool.h"
28 #include "HYDROData_Iterator.h"
29 #include "HYDROData_IAltitudeObject.h"
31 #include <TNaming_Builder.hxx>
32 #include <TNaming_NamedShape.hxx>
34 #include <TopoDS_Shape.hxx>
38 IMPLEMENT_STANDARD_HANDLE(HYDROData_Object,HYDROData_Entity)
39 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Object,HYDROData_Entity)
41 HYDROData_Object::HYDROData_Object()
46 HYDROData_Object::~HYDROData_Object()
50 void HYDROData_Object::SetName( const QString& theName )
52 QString anOldObjName = GetName();
53 if ( anOldObjName != theName )
55 HYDROData_SequenceOfObjects aGroups = GetGroups();
56 HYDROData_SequenceOfObjects::Iterator anIter( aGroups );
57 for ( ; anIter.More(); anIter.Next() )
59 Handle(HYDROData_ShapesGroup) aGroup =
60 Handle(HYDROData_ShapesGroup)::DownCast( anIter.Value() );
61 if ( aGroup.IsNull() )
64 HYDROData_Tool::UpdateChildObjectName( anOldObjName, theName, aGroup );
67 Handle(HYDROData_DummyObject3D) anObject3D = GetObject3D();
68 if ( !anObject3D.IsNull() )
69 HYDROData_Tool::UpdateChildObjectName( anOldObjName, theName, anObject3D );
71 Handle(HYDROData_IAltitudeObject) anAltitudeObj = getChildAltitudeObject();
72 if ( !anAltitudeObj.IsNull() )
73 HYDROData_Tool::UpdateChildObjectName( anOldObjName, theName, anAltitudeObj );
76 HYDROData_Entity::SetName( theName );
79 void HYDROData_Object::Update()
84 checkAndSetAltitudeObject();
85 HYDROData_Entity::Update();
88 HYDROData_SequenceOfObjects HYDROData_Object::GetAllReferenceObjects() const
90 HYDROData_SequenceOfObjects aResSeq = HYDROData_Entity::GetAllReferenceObjects();
92 Handle(HYDROData_IAltitudeObject) aRefAltitude = GetAltitudeObject();
93 if ( !aRefAltitude.IsNull() )
94 aResSeq.Append( aRefAltitude );
99 void HYDROData_Object::SetToUpdate( bool theFlag )
101 HYDROData_Entity::SetToUpdate( theFlag );
103 Handle(HYDROData_DummyObject3D) anObject3D = GetObject3D();
104 if ( !anObject3D.IsNull() )
105 anObject3D->SetToUpdate( theFlag );
108 void HYDROData_Object::SetTopShape( const TopoDS_Shape& theShape )
110 TNaming_Builder aBuilder( myLab.FindChild( DataTag_TopShape ) );
111 aBuilder.Generated( theShape );
114 void HYDROData_Object::SetShape3D( const TopoDS_Shape& theShape )
116 TNaming_Builder aBuilder( myLab.FindChild( DataTag_Shape3D ) );
117 aBuilder.Generated( theShape );
119 // Check the object 3D existance
120 checkAndSetObject3D();
123 Handle(HYDROData_DummyObject3D) HYDROData_Object::GetObject3D() const
125 Handle(HYDROData_DummyObject3D) anObject;
127 TDF_Label aLabel = myLab.FindChild( DataTag_Object3D, false );
128 if ( !aLabel.IsNull() )
130 TDF_Label aChildLabel = aLabel.FindChild( 0, false );
131 if ( !aChildLabel.IsNull() )
133 anObject = Handle(HYDROData_DummyObject3D)::DownCast(
134 HYDROData_Iterator::Object( aChildLabel ) );
141 void HYDROData_Object::checkAndSetObject3D()
143 TDF_Label aLabel = myLab.FindChild( DataTag_Object3D, false );
144 if ( !aLabel.IsNull() )
147 TDF_Label aChildLabel = myLab.FindChild( DataTag_Object3D ).FindChild( 0 );
148 HYDROData_Iterator::CreateObject( aChildLabel, KIND_DUMMY_3D );
151 HYDROData_SequenceOfObjects HYDROData_Object::GetGroups() const
153 return GetReferenceObjects( DataTag_EdgesGroup );
156 Handle(HYDROData_ShapesGroup) HYDROData_Object::GetGroup( const int theGroupId ) const
158 Handle(HYDROData_ShapesGroup) aResGroup;
160 HYDROData_SequenceOfObjects aGroups = GetGroups();
161 if ( theGroupId < 0 || theGroupId >= aGroups.Length() )
164 aResGroup = Handle(HYDROData_ShapesGroup)::DownCast( aGroups.Value( theGroupId + 1 ) );
169 int HYDROData_Object::GetGroupId( const Handle(HYDROData_ShapesGroup)& theGroup ) const
173 HYDROData_SequenceOfObjects aGroups = GetGroups();
174 for ( int i = 1, n = aGroups.Length(); i <= n; ++i )
176 Handle(HYDROData_ShapesGroup) aGroup =
177 Handle(HYDROData_ShapesGroup)::DownCast( aGroups.Value( i ) );
178 if ( IsEqual( theGroup, aGroup ) )
188 bool HYDROData_Object::SetAltitudeObject(
189 const Handle(HYDROData_IAltitudeObject)& theAltitude )
191 if ( theAltitude.IsNull() )
194 Handle(HYDROData_IAltitudeObject) aPrevAltitude = GetAltitudeObject();
195 if ( IsEqual( aPrevAltitude, theAltitude ) )
198 SetReferenceObject( theAltitude, DataTag_AltitudeObject );
200 // Indicate model of the need to update object
206 Handle(HYDROData_IAltitudeObject) HYDROData_Object::GetAltitudeObject() const
208 return Handle(HYDROData_IAltitudeObject)::DownCast(
209 GetReferenceObject( DataTag_AltitudeObject ) );
212 void HYDROData_Object::RemoveAltitudeObject()
214 Handle(HYDROData_IAltitudeObject) aPrevAltitude = GetAltitudeObject();
215 if ( aPrevAltitude.IsNull() )
218 ClearReferenceObjects( DataTag_AltitudeObject );
220 // Indicate model of the need to update object
224 void HYDROData_Object::SetFillingColor( const QColor& theColor )
226 SetColor( theColor, DataTag_FillingColor );
229 QColor HYDROData_Object::GetFillingColor() const
231 return GetColor( getDefaultFillingColor(), DataTag_FillingColor );
234 void HYDROData_Object::SetBorderColor( const QColor& theColor )
236 SetColor( theColor, DataTag_BorderColor );
239 QColor HYDROData_Object::GetBorderColor() const
241 return GetColor( getDefaultBorderColor(), DataTag_BorderColor );
244 QColor HYDROData_Object::getDefaultFillingColor() const
246 return QColor( Qt::yellow );
249 QColor HYDROData_Object::getDefaultBorderColor() const
251 return QColor( Qt::transparent );
254 QStringList HYDROData_Object::dumpObjectCreation( MapOfTreatedObjects& theTreatedObjects ) const
256 QStringList aResList = HYDROData_Entity::dumpObjectCreation( theTreatedObjects );
257 if ( aResList.isEmpty() )
258 return aResList; //Object was not created
260 QStringList aColorsDef;
262 QColor aFillingColor = GetFillingColor();
263 setPythonObjectColor( aColorsDef, aFillingColor, getDefaultFillingColor(), "SetFillingColor" );
265 QColor aBorderColor = GetBorderColor();
266 setPythonObjectColor( aColorsDef, aBorderColor, getDefaultBorderColor(), "SetBorderColor" );
268 if ( !aColorsDef.isEmpty() )
270 aResList << aColorsDef;
271 aResList << QString( "" );
277 ObjectKind HYDROData_Object::getAltitudeObjectType() const
282 Handle(HYDROData_IAltitudeObject) HYDROData_Object::getChildAltitudeObject() const
284 Handle(HYDROData_IAltitudeObject) anObject;
286 TDF_Label aLabel = myLab.FindChild( DataTag_ChildAltitudeObject, false );
287 if ( !aLabel.IsNull() )
289 TDF_Label aChildLabel = aLabel.FindChild( 0, false );
290 if ( !aChildLabel.IsNull() )
292 anObject = Handle(HYDROData_IAltitudeObject)::DownCast(
293 HYDROData_Iterator::Object( aChildLabel ) );
300 void HYDROData_Object::checkAndSetAltitudeObject()
302 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
304 ObjectKind anAltitudeObjectType = getAltitudeObjectType();
305 if ( anAltitudeObjectType == KIND_UNKNOWN )
306 return; // No need to create altitude object
308 TDF_Label aLabel = myLab.FindChild( DataTag_ChildAltitudeObject, false );
309 if ( !aLabel.IsNull() )
312 TDF_Label aChildLabel = myLab.FindChild( DataTag_ChildAltitudeObject ).FindChild( 0 );
314 Handle(HYDROData_IAltitudeObject) anAltitudeObject =
315 Handle(HYDROData_IAltitudeObject)::DownCast(
316 HYDROData_Iterator::CreateObject( aChildLabel, anAltitudeObjectType ) );
318 QString anAltitudePref = GetName() + "_Altitude";
319 QString anAltitudeName = HYDROData_Tool::GenerateObjectName( aDocument, anAltitudePref );
320 anAltitudeObject->SetName( anAltitudeName );
322 SetAltitudeObject( anAltitudeObject );
325 Handle(HYDROData_ShapesGroup) HYDROData_Object::createGroupObject()
327 TDF_Label aNewLab = myLab.FindChild( DataTag_EdgesGroup ).NewChild();
329 Handle(HYDROData_ShapesGroup) aNewGroup =
330 Handle(HYDROData_ShapesGroup)::DownCast( HYDROData_Iterator::CreateObject( aNewLab, KIND_SHAPES_GROUP ) );
331 AddReferenceObject( aNewGroup, DataTag_EdgesGroup );
336 void HYDROData_Object::removeGroupObjects()
338 TDF_Label aLabel = myLab.FindChild( DataTag_EdgesGroup, false );
339 if ( !aLabel.IsNull() )
340 aLabel.ForgetAllAttributes();
343 TopoDS_Shape HYDROData_Object::getTopShape() const
345 TDF_Label aLabel = myLab.FindChild( DataTag_TopShape, false );
346 if ( !aLabel.IsNull() )
348 Handle(TNaming_NamedShape) aNamedShape;
349 if( aLabel.FindAttribute( TNaming_NamedShape::GetID(), aNamedShape ) )
350 return aNamedShape->Get();
353 return TopoDS_Shape();
356 void HYDROData_Object::removeTopShape()
358 TDF_Label aLabel = myLab.FindChild( DataTag_TopShape, false );
359 if ( !aLabel.IsNull() )
360 aLabel.ForgetAllAttributes();
363 TopoDS_Shape HYDROData_Object::getShape3D() const
365 TDF_Label aLabel = myLab.FindChild( DataTag_Shape3D, false );
366 if ( !aLabel.IsNull() )
368 Handle(TNaming_NamedShape) aNamedShape;
369 if( aLabel.FindAttribute( TNaming_NamedShape::GetID(), aNamedShape ) )
370 return aNamedShape->Get();
373 return TopoDS_Shape();
376 void HYDROData_Object::removeShape3D()
378 TDF_Label aLabel = myLab.FindChild( DataTag_Shape3D, false );
379 if ( !aLabel.IsNull() )
380 aLabel.ForgetAllAttributes();