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>
31 #include <TDataStd_Integer.hxx>
35 IMPLEMENT_STANDARD_HANDLE(HYDROData_Object,HYDROData_Entity)
36 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Object,HYDROData_Entity)
38 HYDROData_Object::HYDROData_Object( Geometry theGeometry )
39 : HYDROData_Entity( theGeometry )
43 HYDROData_Object::~HYDROData_Object()
47 void HYDROData_Object::SetName( const QString& theName )
49 QString anOldObjName = GetName();
50 if ( anOldObjName != theName )
52 HYDROData_SequenceOfObjects aGroups = GetGroups();
53 HYDROData_SequenceOfObjects::Iterator anIter( aGroups );
54 for ( ; anIter.More(); anIter.Next() )
56 Handle(HYDROData_ShapesGroup) aGroup =
57 Handle(HYDROData_ShapesGroup)::DownCast( anIter.Value() );
58 if ( aGroup.IsNull() )
61 HYDROData_Tool::UpdateChildObjectName( anOldObjName, theName, aGroup );
64 Handle(HYDROData_DummyObject3D) anObject3D = GetObject3D();
65 if ( !anObject3D.IsNull() )
66 HYDROData_Tool::UpdateChildObjectName( anOldObjName, theName, anObject3D );
68 Handle(HYDROData_IAltitudeObject) anAltitudeObj = getChildAltitudeObject();
69 if ( !anAltitudeObj.IsNull() )
70 HYDROData_Tool::UpdateChildObjectName( anOldObjName, theName, anAltitudeObj );
73 HYDROData_Entity::SetName( theName );
76 void HYDROData_Object::Update()
78 if( IsMustBeUpdated2d() )
83 if( IsMustBeUpdated3d() )
86 checkAndSetAltitudeObject();
87 HYDROData_Entity::Update();
90 HYDROData_SequenceOfObjects HYDROData_Object::GetAllReferenceObjects() const
92 HYDROData_SequenceOfObjects aResSeq = HYDROData_Entity::GetAllReferenceObjects();
94 Handle(HYDROData_IAltitudeObject) aRefAltitude = GetAltitudeObject();
95 if ( !aRefAltitude.IsNull() )
96 aResSeq.Append( aRefAltitude );
101 void HYDROData_Object::Changed( Geometry theChangedGeometry )
103 HYDROData_Entity::Changed( theChangedGeometry );
105 Handle(HYDROData_DummyObject3D) anObject3D = GetObject3D();
106 if ( !anObject3D.IsNull() )
107 anObject3D->Changed( theChangedGeometry );
110 void HYDROData_Object::SetTopShape( const TopoDS_Shape& theShape )
112 TNaming_Builder aBuilder( myLab.FindChild( DataTag_TopShape ) );
113 aBuilder.Generated( theShape );
116 void HYDROData_Object::SetShape3D( const TopoDS_Shape& theShape )
118 TNaming_Builder aBuilder( myLab.FindChild( DataTag_Shape3D ) );
119 aBuilder.Generated( theShape );
121 // Check the object 3D existance
122 checkAndSetObject3D();
125 Handle(HYDROData_DummyObject3D) HYDROData_Object::GetObject3D() const
127 Handle(HYDROData_DummyObject3D) anObject;
129 TDF_Label aLabel = myLab.FindChild( DataTag_Object3D, false );
130 if ( !aLabel.IsNull() )
132 TDF_Label aChildLabel = aLabel.FindChild( 0, false );
133 if ( !aChildLabel.IsNull() )
135 anObject = Handle(HYDROData_DummyObject3D)::DownCast(
136 HYDROData_Iterator::Object( aChildLabel ) );
143 void HYDROData_Object::checkAndSetObject3D()
145 TDF_Label aLabel = myLab.FindChild( DataTag_Object3D, false );
146 if ( !aLabel.IsNull() )
149 TDF_Label aChildLabel = myLab.FindChild( DataTag_Object3D ).FindChild( 0 );
150 HYDROData_Iterator::CreateObject( aChildLabel, KIND_DUMMY_3D );
153 HYDROData_SequenceOfObjects HYDROData_Object::GetGroups() const
155 return GetReferenceObjects( DataTag_EdgesGroup );
158 Handle(HYDROData_ShapesGroup) HYDROData_Object::GetGroup( const int theGroupId ) const
160 Handle(HYDROData_ShapesGroup) aResGroup;
162 HYDROData_SequenceOfObjects aGroups = GetGroups();
163 if ( theGroupId < 0 || theGroupId >= aGroups.Length() )
166 aResGroup = Handle(HYDROData_ShapesGroup)::DownCast( aGroups.Value( theGroupId + 1 ) );
171 int HYDROData_Object::GetGroupId( const Handle(HYDROData_ShapesGroup)& theGroup ) const
175 HYDROData_SequenceOfObjects aGroups = GetGroups();
176 for ( int i = 1, n = aGroups.Length(); i <= n; ++i )
178 Handle(HYDROData_ShapesGroup) aGroup =
179 Handle(HYDROData_ShapesGroup)::DownCast( aGroups.Value( i ) );
180 if ( IsEqual( theGroup, aGroup ) )
190 bool HYDROData_Object::SetAltitudeObject(
191 const Handle(HYDROData_IAltitudeObject)& theAltitude )
193 if ( theAltitude.IsNull() )
196 Handle(HYDROData_IAltitudeObject) aPrevAltitude = GetAltitudeObject();
197 if ( IsEqual( aPrevAltitude, theAltitude ) )
200 SetReferenceObject( theAltitude, DataTag_AltitudeObject );
202 // #636: In the case of the altitude object change the geometry of the main object is not changed,
203 // to the object should not be marked as updated
204 //SetToUpdate( true );
209 Handle(HYDROData_IAltitudeObject) HYDROData_Object::GetAltitudeObject() const
211 return Handle(HYDROData_IAltitudeObject)::DownCast(
212 GetReferenceObject( DataTag_AltitudeObject ) );
215 void HYDROData_Object::RemoveAltitudeObject()
217 Handle(HYDROData_IAltitudeObject) aPrevAltitude = GetAltitudeObject();
218 if ( aPrevAltitude.IsNull() )
221 ClearReferenceObjects( DataTag_AltitudeObject );
223 // #636: In the case of the altitude object change the geometry of the main object is not changed,
224 // to the object should not be marked as updated
225 //SetToUpdate( true );
228 void HYDROData_Object::SetFillingColor( const QColor& theColor )
230 SetColor( theColor, DataTag_FillingColor );
233 QColor HYDROData_Object::GetFillingColor() const
235 return GetColor( getDefaultFillingColor(), DataTag_FillingColor );
238 void HYDROData_Object::SetBorderColor( const QColor& theColor )
240 SetColor( theColor, DataTag_BorderColor );
243 QColor HYDROData_Object::GetBorderColor() const
245 return GetColor( getDefaultBorderColor(), DataTag_BorderColor );
248 QColor HYDROData_Object::getDefaultFillingColor() const
250 return QColor( Qt::yellow );
253 QColor HYDROData_Object::getDefaultBorderColor() const
255 return QColor( Qt::transparent );
258 QStringList HYDROData_Object::dumpObjectCreation( MapOfTreatedObjects& theTreatedObjects ) const
260 QStringList aResList = HYDROData_Entity::dumpObjectCreation( theTreatedObjects );
261 if ( aResList.isEmpty() )
262 return aResList; //Object was not created
264 QStringList aColorsDef;
266 QColor aFillingColor = GetFillingColor();
267 setPythonObjectColor( aColorsDef, aFillingColor, getDefaultFillingColor(), "SetFillingColor" );
269 QColor aBorderColor = GetBorderColor();
270 setPythonObjectColor( aColorsDef, aBorderColor, getDefaultBorderColor(), "SetBorderColor" );
272 if ( !aColorsDef.isEmpty() )
274 aResList << aColorsDef;
275 aResList << QString( "" );
281 ObjectKind HYDROData_Object::getAltitudeObjectType() const
286 Handle(HYDROData_IAltitudeObject) HYDROData_Object::getChildAltitudeObject() const
288 Handle(HYDROData_IAltitudeObject) anObject;
290 TDF_Label aLabel = myLab.FindChild( DataTag_ChildAltitudeObject, false );
291 if ( !aLabel.IsNull() )
293 TDF_Label aChildLabel = aLabel.FindChild( 0, false );
294 if ( !aChildLabel.IsNull() )
296 anObject = Handle(HYDROData_IAltitudeObject)::DownCast(
297 HYDROData_Iterator::Object( aChildLabel ) );
304 void HYDROData_Object::checkAndSetAltitudeObject()
306 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
308 ObjectKind anAltitudeObjectType = getAltitudeObjectType();
309 if ( anAltitudeObjectType == KIND_UNKNOWN )
310 return; // No need to create altitude object
312 TDF_Label aLabel = myLab.FindChild( DataTag_ChildAltitudeObject, false );
313 if ( !aLabel.IsNull() )
316 TDF_Label aChildLabel = myLab.FindChild( DataTag_ChildAltitudeObject ).FindChild( 0 );
318 Handle(HYDROData_IAltitudeObject) anAltitudeObject =
319 Handle(HYDROData_IAltitudeObject)::DownCast(
320 HYDROData_Iterator::CreateObject( aChildLabel, anAltitudeObjectType ) );
322 QString anAltitudePref = GetName() + "_Altitude";
323 QString anAltitudeName = HYDROData_Tool::GenerateObjectName( aDocument, anAltitudePref );
324 anAltitudeObject->SetName( anAltitudeName );
326 SetAltitudeObject( anAltitudeObject );
329 Handle(HYDROData_ShapesGroup) HYDROData_Object::createGroupObject()
331 TDF_Label aNewLab = myLab.FindChild( DataTag_EdgesGroup ).NewChild();
333 Handle(HYDROData_ShapesGroup) aNewGroup =
334 Handle(HYDROData_ShapesGroup)::DownCast( HYDROData_Iterator::CreateObject( aNewLab, KIND_SHAPES_GROUP ) );
335 AddReferenceObject( aNewGroup, DataTag_EdgesGroup );
340 void HYDROData_Object::removeGroupObjects()
342 TDF_Label aLabel = myLab.FindChild( DataTag_EdgesGroup, false );
343 if ( !aLabel.IsNull() )
344 aLabel.ForgetAllAttributes();
347 TopoDS_Shape HYDROData_Object::getTopShape() const
349 TDF_Label aLabel = myLab.FindChild( DataTag_TopShape, false );
350 if ( !aLabel.IsNull() )
352 Handle(TNaming_NamedShape) aNamedShape;
353 if( aLabel.FindAttribute( TNaming_NamedShape::GetID(), aNamedShape ) )
354 return aNamedShape->Get();
357 return TopoDS_Shape();
360 void HYDROData_Object::removeTopShape()
362 TDF_Label aLabel = myLab.FindChild( DataTag_TopShape, false );
363 if ( !aLabel.IsNull() )
364 aLabel.ForgetAllAttributes();
367 TopoDS_Shape HYDROData_Object::getShape3D() const
369 TDF_Label aLabel = myLab.FindChild( DataTag_Shape3D, false );
370 if ( !aLabel.IsNull() )
372 Handle(TNaming_NamedShape) aNamedShape;
373 if( aLabel.FindAttribute( TNaming_NamedShape::GetID(), aNamedShape ) )
374 return aNamedShape->Get();
377 return TopoDS_Shape();
380 void HYDROData_Object::removeShape3D()
382 TDF_Label aLabel = myLab.FindChild( DataTag_Shape3D, false );
383 if ( !aLabel.IsNull() )
384 aLabel.ForgetAllAttributes();
387 bool HYDROData_Object::IsSubmersible() const
389 Handle(TDataStd_Integer) aSubMersibleAttr;
391 bool isSubmersible = true; //default
392 if( myLab.FindAttribute(TDataStd_Integer::GetID(), aSubMersibleAttr ) )
394 int aValue = aSubMersibleAttr->Get();
395 isSubmersible = ( aValue != 0 );
397 return isSubmersible;
400 void HYDROData_Object::SetIsSubmersible( bool isSubmersible ) const
402 TDataStd_Integer::Set( myLab, isSubmersible ? 1 : 0 );