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"
26 #include <TopoDS_Shape.hxx>
27 #include <TDataStd_Integer.hxx>
31 IMPLEMENT_STANDARD_HANDLE(HYDROData_Object,HYDROData_Entity)
32 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Object,HYDROData_Entity)
34 HYDROData_Object::HYDROData_Object()
39 HYDROData_Object::~HYDROData_Object()
43 void HYDROData_Object::SetName( const QString& theName )
45 QString anOldObjName = GetName();
46 if ( anOldObjName != theName )
48 HYDROData_SequenceOfObjects aGroups = GetGroups();
49 HYDROData_SequenceOfObjects::Iterator anIter( aGroups );
50 for ( ; anIter.More(); anIter.Next() )
52 Handle(HYDROData_ShapesGroup) aGroup =
53 Handle(HYDROData_ShapesGroup)::DownCast( anIter.Value() );
54 if ( aGroup.IsNull() )
57 HYDROData_Tool::UpdateChildObjectName( anOldObjName, theName, aGroup );
60 Handle(HYDROData_DummyObject3D) anObject3D = GetObject3D();
61 if ( !anObject3D.IsNull() )
62 HYDROData_Tool::UpdateChildObjectName( anOldObjName, theName, anObject3D );
64 Handle(HYDROData_IAltitudeObject) anAltitudeObj = getChildAltitudeObject();
65 if ( !anAltitudeObj.IsNull() )
66 HYDROData_Tool::UpdateChildObjectName( anOldObjName, theName, anAltitudeObj );
69 HYDROData_Entity::SetName( theName );
72 void HYDROData_Object::Update()
77 checkAndSetAltitudeObject();
78 HYDROData_Entity::Update();
81 HYDROData_SequenceOfObjects HYDROData_Object::GetAllReferenceObjects() const
83 HYDROData_SequenceOfObjects aResSeq = HYDROData_Entity::GetAllReferenceObjects();
85 Handle(HYDROData_IAltitudeObject) aRefAltitude = GetAltitudeObject();
86 if ( !aRefAltitude.IsNull() )
87 aResSeq.Append( aRefAltitude );
92 void HYDROData_Object::SetToUpdate( bool theFlag )
94 HYDROData_Entity::SetToUpdate( theFlag );
96 Handle(HYDROData_DummyObject3D) anObject3D = GetObject3D();
97 if ( !anObject3D.IsNull() )
98 anObject3D->SetToUpdate( theFlag );
101 void HYDROData_Object::SetTopShape( const TopoDS_Shape& theShape )
103 HYDROData_Entity::SetShape( DataTag_TopShape, theShape );
106 TopoDS_Shape HYDROData_Object::GetTopShape() const
108 return HYDROData_Entity::GetShape( DataTag_TopShape );
111 void HYDROData_Object::SetShape3D( const TopoDS_Shape& theShape )
113 HYDROData_Entity::SetShape( DataTag_Shape3D, theShape );
114 // Check the object 3D existance
115 checkAndSetObject3D();
118 TopoDS_Shape HYDROData_Object::GetShape3D() const
120 return HYDROData_Entity::GetShape( DataTag_Shape3D );
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 // #636: In the case of the altitude object change the geometry of the main object is not changed,
201 // to the object should not be marked as updated
202 //SetToUpdate( true );
207 Handle(HYDROData_IAltitudeObject) HYDROData_Object::GetAltitudeObject() const
209 return Handle(HYDROData_IAltitudeObject)::DownCast(
210 GetReferenceObject( DataTag_AltitudeObject ) );
213 void HYDROData_Object::RemoveAltitudeObject()
215 Handle(HYDROData_IAltitudeObject) aPrevAltitude = GetAltitudeObject();
216 if ( aPrevAltitude.IsNull() )
219 ClearReferenceObjects( DataTag_AltitudeObject );
221 // #636: In the case of the altitude object change the geometry of the main object is not changed,
222 // to the object should not be marked as updated
223 //SetToUpdate( true );
226 void HYDROData_Object::SetFillingColor( const QColor& theColor )
228 SetColor( theColor, DataTag_FillingColor );
231 QColor HYDROData_Object::GetFillingColor() const
233 return GetColor( getDefaultFillingColor(), DataTag_FillingColor );
236 void HYDROData_Object::SetBorderColor( const QColor& theColor )
238 SetColor( theColor, DataTag_BorderColor );
241 QColor HYDROData_Object::GetBorderColor() const
243 return GetColor( getDefaultBorderColor(), DataTag_BorderColor );
246 QColor HYDROData_Object::getDefaultFillingColor() const
248 return QColor( Qt::yellow );
251 QColor HYDROData_Object::getDefaultBorderColor() const
253 return QColor( Qt::transparent );
256 QStringList HYDROData_Object::dumpObjectCreation( MapOfTreatedObjects& theTreatedObjects ) const
258 QStringList aResList = HYDROData_Entity::dumpObjectCreation( theTreatedObjects );
259 if ( aResList.isEmpty() )
260 return aResList; //Object was not created
262 QStringList aColorsDef;
264 QColor aFillingColor = GetFillingColor();
265 setPythonObjectColor( aColorsDef, aFillingColor, getDefaultFillingColor(), "SetFillingColor" );
267 QColor aBorderColor = GetBorderColor();
268 setPythonObjectColor( aColorsDef, aBorderColor, getDefaultBorderColor(), "SetBorderColor" );
270 if ( !aColorsDef.isEmpty() )
272 aResList << aColorsDef;
273 aResList << QString( "" );
279 ObjectKind HYDROData_Object::getAltitudeObjectType() const
284 Handle(HYDROData_IAltitudeObject) HYDROData_Object::getChildAltitudeObject() const
286 Handle(HYDROData_IAltitudeObject) anObject;
288 TDF_Label aLabel = myLab.FindChild( DataTag_ChildAltitudeObject, false );
289 if ( !aLabel.IsNull() )
291 TDF_Label aChildLabel = aLabel.FindChild( 0, false );
292 if ( !aChildLabel.IsNull() )
294 anObject = Handle(HYDROData_IAltitudeObject)::DownCast(
295 HYDROData_Iterator::Object( aChildLabel ) );
302 void HYDROData_Object::checkAndSetAltitudeObject()
304 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
306 ObjectKind anAltitudeObjectType = getAltitudeObjectType();
307 if ( anAltitudeObjectType == KIND_UNKNOWN )
308 return; // No need to create altitude object
310 TDF_Label aLabel = myLab.FindChild( DataTag_ChildAltitudeObject, false );
311 if ( !aLabel.IsNull() )
314 TDF_Label aChildLabel = myLab.FindChild( DataTag_ChildAltitudeObject ).FindChild( 0 );
316 Handle(HYDROData_IAltitudeObject) anAltitudeObject =
317 Handle(HYDROData_IAltitudeObject)::DownCast(
318 HYDROData_Iterator::CreateObject( aChildLabel, anAltitudeObjectType ) );
320 QString anAltitudePref = GetName() + "_Altitude";
321 QString anAltitudeName = HYDROData_Tool::GenerateObjectName( aDocument, anAltitudePref );
322 anAltitudeObject->SetName( anAltitudeName );
324 SetAltitudeObject( anAltitudeObject );
327 Handle(HYDROData_ShapesGroup) HYDROData_Object::createGroupObject()
329 TDF_Label aNewLab = myLab.FindChild( DataTag_EdgesGroup ).NewChild();
331 Handle(HYDROData_ShapesGroup) aNewGroup =
332 Handle(HYDROData_ShapesGroup)::DownCast( HYDROData_Iterator::CreateObject( aNewLab, KIND_SHAPES_GROUP ) );
333 AddReferenceObject( aNewGroup, DataTag_EdgesGroup );
338 void HYDROData_Object::RemoveGroupObjects()
340 TDF_Label aLabel = myLab.FindChild( DataTag_EdgesGroup, false );
341 if ( !aLabel.IsNull() )
342 aLabel.ForgetAllAttributes();
345 void HYDROData_Object::RemoveTopShape()
347 HYDROData_Entity::SetShape( DataTag_TopShape, TopoDS_Shape() );
350 void HYDROData_Object::RemoveShape3D()
352 HYDROData_Entity::SetShape( DataTag_Shape3D, TopoDS_Shape() );
355 bool HYDROData_Object::IsSubmersible() const
357 Handle(TDataStd_Integer) aSubMersibleAttr;
359 bool isSubmersible = true; //default
360 if( myLab.FindAttribute(TDataStd_Integer::GetID(), aSubMersibleAttr ) )
362 int aValue = aSubMersibleAttr->Get();
363 isSubmersible = ( aValue != 0 );
365 return isSubmersible;
368 void HYDROData_Object::SetIsSubmersible( bool isSubmersible ) const
370 TDataStd_Integer::Set( myLab, isSubmersible ? 1 : 0 );