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_Entity.h>
20 #include <HYDROData_Document.h>
21 #include <HYDROData_Iterator.h>
22 #include <HYDROData_Tool.h>
23 #include <Standard_GUID.hxx>
24 #include <TDataStd_Name.hxx>
25 #include <TDataStd_ByteArray.hxx>
26 #include <TDataStd_UAttribute.hxx>
27 #include <TDataStd_AsciiString.hxx>
28 #include <TDataStd_Integer.hxx>
29 #include <TDataStd_IntegerArray.hxx>
30 #include <TDataStd_ReferenceList.hxx>
31 #include <TDataStd_Real.hxx>
32 #include <TDF_CopyLabel.hxx>
33 #include <TDF_ListIteratorOfLabelList.hxx>
34 #include <TNaming_Builder.hxx>
35 #include <TNaming_NamedShape.hxx>
36 #include <TopoDS_Shape.hxx>
39 #include <QStringList>
43 #include "HYDRO_trace.hxx"
45 HYDROData_SequenceOfObjects::HYDROData_SequenceOfObjects()
46 : NCollection_Sequence<Handle(HYDROData_Entity)>()
50 HYDROData_SequenceOfObjects::HYDROData_SequenceOfObjects( const HYDROData_SequenceOfObjects& theSequence )
51 : NCollection_Sequence<Handle(HYDROData_Entity)>( theSequence )
55 HYDROData_SequenceOfObjects::HYDROData_SequenceOfObjects( const NCollection_Sequence<Handle(HYDROData_Entity)>& theSequence )
56 : NCollection_Sequence<Handle(HYDROData_Entity)>( theSequence )
60 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Entity,MMgt_TShared)
62 // is equal function for unique object mapping
63 bool IsEqual(const Handle(HYDROData_Entity)& theObj1, const Handle(HYDROData_Entity)& theObj2)
65 if ( !theObj1.IsNull() && !theObj2.IsNull() )
66 return theObj1->Label() == theObj2->Label();
70 QString HYDROData_Entity::GetName() const
72 Handle(TDataStd_Name) aName;
73 if (myLab.FindAttribute(TDataStd_Name::GetID(), aName)) {
74 TCollection_AsciiString aStr(aName->Get());
75 return QString(aStr.ToCString());
80 QString HYDROData_Entity::GetObjPyName() const
82 QString aName = GetName();
83 aName.replace(QRegExp("[\\W]"), "_");
88 QString HYDROData_Entity::GetDefaultName() const
92 TDF_Label aLabel = myLab.FindChild(DataTag_DefaultName, false);
95 Handle(TDataStd_AsciiString) anAsciiStr;
96 if (aLabel.FindAttribute(TDataStd_AsciiString::GetID(), anAsciiStr))
97 aName = QString(anAsciiStr->Get().ToCString());
106 void HYDROData_Entity::SetName(const QString& theName, bool isDefault)
108 TDataStd_Name::Set(myLab, TCollection_ExtendedString(theName.toLatin1().constData()));
111 TDF_Label aDefaultNameLabel = myLab.FindChild( DataTag_DefaultName, true );
112 if ( aDefaultNameLabel.IsNull() )
114 Handle(TDataStd_AsciiString) theDefaultName;
116 if ( !aDefaultNameLabel.FindAttribute( TDataStd_AsciiString::GetID(), theDefaultName ))
118 TCollection_AsciiString aName = theName.toStdString().c_str();
119 theDefaultName = TDataStd_AsciiString::Set(myLab.FindChild( DataTag_DefaultName), aName );
124 QStringList HYDROData_Entity::DumpToPython( const QString& thePyScriptPath,
125 MapOfTreatedObjects& theTreatedObjects ) const
127 QStringList anEmptyList;
131 void HYDROData_Entity::Update()
136 void HYDROData_Entity::UpdateLocalCS( double theDx, double theDy )
138 //On the base level no actions are necessary
141 bool HYDROData_Entity::IsHas2dPrs() const
146 void HYDROData_Entity::Show()
151 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
152 if ( aDocument.IsNull() )
155 aDocument->Show( this );
158 QVariant HYDROData_Entity::GetDataVariant()
163 void HYDROData_Entity::ClearChanged()
165 TDataStd_Integer::Set( myLab.FindChild( DataTag_GeomChange ), 0 );
168 int HYDROData_Entity::GetGeomChangeFlag() const
170 int aGeomChangeFlag = 0;
171 Handle(TDataStd_Integer) aGeomChangeAttr;
172 TDF_Label aGeomChangeLab = myLab.FindChild( DataTag_GeomChange );
173 aGeomChangeLab.FindAttribute( TDataStd_Integer::GetID(), aGeomChangeAttr );
174 if ( !aGeomChangeAttr.IsNull() )
175 aGeomChangeFlag = aGeomChangeAttr->Get();
176 return aGeomChangeFlag;
179 void HYDROData_Entity::Changed( Geometry theChangedGeometry )
181 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
182 if( aDocument.IsNull() )
185 int aGeomChangeFlag = 0;
186 Handle(TDataStd_Integer) aGeomChangeAttr;
187 TDF_Label aGeomChangeLab = myLab.FindChild( DataTag_GeomChange );
188 aGeomChangeLab.FindAttribute( TDataStd_Integer::GetID(), aGeomChangeAttr );
189 if ( !aGeomChangeAttr.IsNull() )
190 aGeomChangeFlag = aGeomChangeAttr->Get();
192 int aBitsToChange = ( myGeom & theChangedGeometry );
193 if( aBitsToChange == 0 )
196 aGeomChangeFlag = ( aGeomChangeFlag | aBitsToChange );
197 TDataStd_Integer::Set( aGeomChangeLab, aGeomChangeFlag );
199 HYDROData_Iterator anIter( aDocument );
200 for ( ; anIter.More(); anIter.Next() )
202 Handle(HYDROData_Entity) anObject = anIter.Current();
203 if( anObject.IsNull() )
205 HYDROData_SequenceOfObjects aRefSeq = anObject->GetAllReferenceObjects();
206 for ( int i = 1, n = aRefSeq.Length(); i <= n; ++i )
208 Handle(HYDROData_Entity) aRefObject = aRefSeq.Value( i );
209 if( aRefObject->Label()==myLab )
210 anObject->Changed( theChangedGeometry );
215 bool HYDROData_Entity::IsMustBeUpdated( Geometry theGeom ) const
217 return ( ( GetGeomChangeFlag() & theGeom ) != 0 );
220 bool HYDROData_Entity::CanBeUpdated() const
225 bool HYDROData_Entity::IsRemoved() const
227 return !myLab.HasAttribute();
230 void HYDROData_Entity::Remove()
232 return myLab.ForgetAllAttributes( true );
235 bool HYDROData_Entity::CanRemove()
240 HYDROData_Entity::HYDROData_Entity( Geometry theGeom )
245 HYDROData_Entity::~HYDROData_Entity()
249 void HYDROData_Entity::CopyTo( const Handle(HYDROData_Entity)& theDestination,
250 bool isGenerateNewName ) const
252 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
253 if ( aDocument.IsNull() ) {
257 TDF_CopyLabel aCopy(myLab, theDestination->Label());
260 if( isGenerateNewName )
262 // generate a new unique name for the clone object:
263 // case 1: Image_1 -> Image_2
264 // case 2: ImageObj -> ImageObj_1
265 QString aName = theDestination->GetName();
266 QString aPrefix = aName;
267 if( aName.contains( '_' ) ) { // case 1
268 QString aSuffix = aName.section( '_', -1 );
269 bool anIsInteger = false;
270 aSuffix.toInt( &anIsInteger );
272 aPrefix = aName.section( '_', 0, -2 );
277 aName = HYDROData_Tool::GenerateObjectName( aDocument, aPrefix );
278 theDestination->SetName( aName );
282 Handle(HYDROData_Entity) HYDROData_Entity::GetFatherObject() const
284 Handle(HYDROData_Entity) aFather;
286 if ( !myLab.IsNull() )
288 TDF_Label aFatherLabel = myLab.Father();
290 while ( aFather.IsNull() && !aFatherLabel.IsNull() && !aFatherLabel.IsRoot() )
292 aFather = HYDROData_Iterator::Object( aFatherLabel );
293 aFatherLabel = aFatherLabel.Father();
300 HYDROData_SequenceOfObjects HYDROData_Entity::GetAllReferenceObjects() const
302 return HYDROData_SequenceOfObjects();
305 bool HYDROData_Entity::GetZLevel( Standard_Integer& theLevel ) const
309 TDF_Label aLabel = myLab.FindChild( DataTag_ZLevel, false );
310 if ( !aLabel.IsNull() )
312 Handle(TDataStd_Integer) anIntVal;
313 if ( aLabel.FindAttribute( TDataStd_Integer::GetID(), anIntVal ) )
315 theLevel = anIntVal->Get();
323 void HYDROData_Entity::SetZLevel( const Standard_Integer& theLevel )
325 TDataStd_Integer::Set( myLab.FindChild( DataTag_ZLevel ), theLevel );
328 void HYDROData_Entity::RemoveZLevel()
330 TDF_Label aLabel = myLab.FindChild( DataTag_ZLevel, false );
331 if ( !aLabel.IsNull() )
332 aLabel.ForgetAllAttributes();
335 void HYDROData_Entity::SetLabel( const TDF_Label& theLabel )
340 void HYDROData_Entity::SaveByteArray( const int theTag,
344 TDF_Label aLab = theTag == 0 ? myLab : myLab.FindChild(theTag);
345 // array is empty, remove the attribute
347 aLab.ForgetAttribute(TDataStd_ByteArray::GetID());
350 // store data of image in byte array
351 Handle(TDataStd_ByteArray) aData;
352 if (!aLab.FindAttribute(TDataStd_ByteArray::GetID(), aData)) {
353 aData = TDataStd_ByteArray::Set(aLab, 1, theLen);
355 // copy bytes one by one
356 if (aData->Length() != theLen) {
357 Handle(TColStd_HArray1OfByte) aNewData = new TColStd_HArray1OfByte(1, theLen);
358 for(int a = 0; a < theLen; a++)
359 aNewData->SetValue(a + 1, theData[a]);
360 aData->ChangeArray(aNewData);
362 for(int a = 0; a < theLen; a++)
363 aData->SetValue(a + 1, theData[a]);
367 const char* HYDROData_Entity::ByteArray(const int theTag, int& theLen) const
369 TDF_Label aLab = theTag == 0 ? myLab : myLab.FindChild(theTag);
370 Handle(TDataStd_ByteArray) aData;
371 if (!aLab.FindAttribute(TDataStd_ByteArray::GetID(), aData))
372 return NULL; // return empty image if there is no array
373 theLen = aData->Length();
375 return (const char*)(&(aData->InternalArray()->ChangeArray1().ChangeValue(1)));
379 int HYDROData_Entity::NbReferenceObjects( const int theTag ) const
381 Handle(TDataStd_ReferenceList) aRefs = getReferenceList( theTag, false );
382 return aRefs.IsNull() ? 0 : aRefs->Extent();
385 bool HYDROData_Entity::HasReference( const Handle(HYDROData_Entity)& theObj,
386 const int theTag ) const
388 if ( theObj.IsNull() )
391 Handle(TDataStd_ReferenceList) aRefs = getReferenceList( theTag, false );
392 if ( aRefs.IsNull() || aRefs->IsEmpty() )
395 TDF_ListIteratorOfLabelList aListIt( aRefs->List() );
396 for ( ; aListIt.More(); aListIt.Next() )
398 const TDF_Label& aRefLabel = aListIt.Value();
399 if ( theObj->Label() == aRefLabel )
406 void HYDROData_Entity::AddReferenceObject( const Handle(HYDROData_Entity)& theObj,
409 if ( theObj.IsNull() )
412 Handle(TDataStd_ReferenceList) aRefs = getReferenceList( theTag, true );
413 aRefs->Append( theObj->Label() );
416 void HYDROData_Entity::SetReferenceObject( const Handle(HYDROData_Entity)& theObj,
420 if ( theObj.IsNull() )
422 RemoveReferenceObject( theTag, theIndex );
426 Handle(TDataStd_ReferenceList) aRefs = getReferenceList( theTag, true );
428 if ( theIndex >= aRefs->Extent() )
430 aRefs->Append( theObj->Label() );
432 else if ( theIndex < 0 )
434 aRefs->Prepend( theObj->Label() );
438 RemoveReferenceObject( theTag, theIndex );
440 Handle(HYDROData_Entity) aBeforeObj = GetReferenceObject( theTag, theIndex );
442 aRefs = getReferenceList( theTag, true ); // because reference list can be removed
443 if ( !aBeforeObj.IsNull() )
444 aRefs->InsertBefore( theObj->Label(), aBeforeObj->Label() );
446 aRefs->Append( theObj->Label() );
450 void HYDROData_Entity::InsertReferenceObject( const Handle(HYDROData_Entity)& theObj,
452 const int theBeforeIndex )
454 if ( theObj.IsNull() )
457 Handle(TDataStd_ReferenceList) aRefs = getReferenceList( theTag, true );
459 if ( theBeforeIndex >= aRefs->Extent() )
461 aRefs->Append( theObj->Label() );
463 else if ( theBeforeIndex < 0 )
465 aRefs->Prepend( theObj->Label() );
469 Handle(HYDROData_Entity) aBeforeObj = GetReferenceObject( theTag, theBeforeIndex );
470 if ( !aBeforeObj.IsNull() )
471 aRefs->InsertBefore( theObj->Label(), aBeforeObj->Label() );
473 aRefs->Append( theObj->Label() );
477 void HYDROData_Entity::SetReferenceObjects( const HYDROData_SequenceOfObjects& theObjects,
480 ClearReferenceObjects( theTag );
481 if ( theObjects.IsEmpty() )
484 HYDROData_SequenceOfObjects::Iterator anIter( theObjects );
485 for ( ; anIter.More(); anIter.Next() )
486 AddReferenceObject( anIter.Value(), theTag );
489 Handle(HYDROData_Entity) HYDROData_Entity::GetReferenceObject( const int theTag,
490 const int theIndex ) const
492 Handle(HYDROData_Entity) aRes;
494 Handle(TDataStd_ReferenceList) aRefs = getReferenceList( theTag, false );
495 if ( aRefs.IsNull() || theIndex < 0 || theIndex >= aRefs->Extent() )
498 TDF_ListIteratorOfLabelList anIter( aRefs->List() );
499 for ( int anIndex = 0; anIndex != theIndex && anIter.More(); anIter.Next(), ++anIndex );
501 const TDF_Label& aRefLabel = anIter.Value();
502 aRes = HYDROData_Iterator::Object( aRefLabel );
507 HYDROData_SequenceOfObjects HYDROData_Entity::GetReferenceObjects( const int theTag ) const
509 HYDROData_SequenceOfObjects aRes;
511 Handle(TDataStd_ReferenceList) aRefs = getReferenceList( theTag, false );
512 if ( aRefs.IsNull() )
515 TDF_ListIteratorOfLabelList anIter( aRefs->List() );
516 for ( ; anIter.More(); anIter.Next() )
518 const TDF_Label& aRefLabel = anIter.Value();
520 Handle(HYDROData_Entity) aRefObject = HYDROData_Iterator::Object( aRefLabel );
521 if ( aRefObject.IsNull() )
524 aRes.Append( aRefObject );
530 void HYDROData_Entity::RemoveReferenceObject( const TDF_Label& theRefLabel,
533 Handle(TDataStd_ReferenceList) aRefs = getReferenceList( theTag, false );
534 if ( aRefs.IsNull() )
537 if ( aRefs->Extent() == 1 )
539 // remove all if only one
540 ClearReferenceObjects( theTag );
544 aRefs->Remove( theRefLabel );
547 void HYDROData_Entity::RemoveReferenceObject( const int theTag,
550 Handle(TDataStd_ReferenceList) aRefs = getReferenceList( theTag, false );
551 if ( aRefs.IsNull() )
554 if ( aRefs->Extent() == 1 && theIndex == 0 )
556 // remove all if only one
557 ClearReferenceObjects( theTag );
562 TDF_ListIteratorOfLabelList anIter( aRefs->List() );
563 for ( ; anIndex != theIndex && anIter.More(); anIter.Next(), ++anIndex );
565 if ( anIndex != theIndex || !anIter.More() )
568 const TDF_Label& aRefLabel = anIter.Value();
569 aRefs->Remove( aRefLabel );
572 void HYDROData_Entity::ClearReferenceObjects( const int theTag )
574 TDF_Label aSetLabel = theTag == 0 ? myLab : myLab.FindChild( theTag );
575 aSetLabel.ForgetAttribute( TDataStd_ReferenceList::GetID() );
578 Handle(TDataStd_ReferenceList) HYDROData_Entity::getReferenceList( const int theTag,
579 const bool theIsCreate ) const
581 TDF_Label aLabel = theTag == 0 ? myLab : myLab.FindChild( theTag );
583 Handle(TDataStd_ReferenceList) aRefs;
584 if ( !aLabel.FindAttribute( TDataStd_ReferenceList::GetID(), aRefs ) && theIsCreate )
585 aRefs = TDataStd_ReferenceList::Set( aLabel );
590 void HYDROData_Entity::SetColor( const QColor& theColor,
593 TDF_Label aLabel = theTag == 0 ? myLab : myLab.FindChild( theTag );
595 Handle(TDataStd_IntegerArray) aColorArray;
596 if ( !aLabel.FindAttribute( TDataStd_IntegerArray::GetID(), aColorArray ) )
597 aColorArray = TDataStd_IntegerArray::Set( aLabel, 1, 4 );
599 aColorArray->SetValue( 1, theColor.red() );
600 aColorArray->SetValue( 2, theColor.green() );
601 aColorArray->SetValue( 3, theColor.blue() );
602 aColorArray->SetValue( 4, theColor.alpha() );
605 QColor HYDROData_Entity::GetColor( const QColor& theDefColor,
606 const int theTag ) const
608 QColor aResColor = theDefColor;
610 TDF_Label aLabel = theTag == 0 ? myLab : myLab.FindChild( theTag );
612 Handle(TDataStd_IntegerArray) aColorArray;
613 if ( aLabel.FindAttribute( TDataStd_IntegerArray::GetID(), aColorArray ) )
615 aResColor.setRed( aColorArray->Value( 1 ) );
616 aResColor.setGreen( aColorArray->Value( 2 ) );
617 aResColor.setBlue( aColorArray->Value( 3 ) );
618 aResColor.setAlpha( aColorArray->Value( 4 ) );
624 QStringList HYDROData_Entity::dumpObjectCreation( MapOfTreatedObjects& theTreatedObjects ) const
626 QStringList aResList;
628 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
629 if ( aDocument.IsNull() )
632 QString aDocName = aDocument->GetDocPyName();
633 QString aName = GetObjPyName();
635 aResList << QString( "%1 = %2.CreateObject( %3 )" )
636 .arg( aName ).arg( aDocName ).arg( getPyTypeID() );
637 aResList << QString( "%1.SetName( \"%2\" )" )
638 .arg( aName ).arg( GetName() );
639 aResList << QString( "" );
643 // Dump object z-level in viewer
644 Standard_Integer anObjZLevel = -1;
645 if ( GetZLevel( anObjZLevel ) )
647 aResList << QString( "%1.SetZLevel( %2 )" )
648 .arg( aName ).arg( anObjZLevel );
649 aResList << QString( "" );
656 QString HYDROData_Entity::getPyTypeID() const
658 //DEBTRACE("HYDROData_Entity::getPyTypeID " << GetKind());
661 case KIND_IMAGE: return "KIND_IMAGE";
662 case KIND_POLYLINE: return "KIND_POLYLINE";
663 case KIND_BATHYMETRY: return "KIND_BATHYMETRY";
664 case KIND_ALTITUDE: return "KIND_ALTITUDE";
665 case KIND_IMMERSIBLE_ZONE: return "KIND_IMMERSIBLE_ZONE";
666 case KIND_RIVER: return "KIND_RIVER";
667 case KIND_STREAM: return "KIND_STREAM";
668 case KIND_CONFLUENCE: return "KIND_CONFLUENCE";
669 case KIND_CHANNEL: return "KIND_CHANNEL";
670 case KIND_OBSTACLE: return "KIND_OBSTACLE";
671 case KIND_DIGUE: return "KIND_DIGUE";
672 case KIND_PROFILE: return "KIND_PROFILE";
673 case KIND_PROFILEUZ: return "KIND_PROFILEUZ";
674 case KIND_POLYLINEXY: return "KIND_POLYLINEXY";
675 case KIND_CALCULATION: return "KIND_CALCULATION";
676 case KIND_ZONE: return "KIND_ZONE";
677 case KIND_REGION: return "KIND_REGION";
678 case KIND_VISUAL_STATE: return "KIND_VISUAL_STATE";
679 case KIND_ARTIFICIAL_OBJECT: return "KIND_ARTIFICIAL_OBJECT";
680 case KIND_NATURAL_OBJECT: return "KIND_NATURAL_OBJECT";
681 case KIND_DUMMY_3D: return "KIND_DUMMY_3D";
682 case KIND_SHAPES_GROUP: return "KIND_SHAPES_GROUP";
683 case KIND_SPLIT_GROUP: return "KIND_SPLIT_GROUP";
684 case KIND_STREAM_ALTITUDE: return "KIND_STREAM_ALTITUDE";
685 case KIND_OBSTACLE_ALTITUDE: return "KIND_OBSTACLE_ALTITUDE";
686 case KIND_STRICKLER_TABLE: return "KIND_STRICKLER_TABLE";
687 case KIND_LAND_COVER_OBSOLETE: return "";
688 case KIND_CHANNEL_ALTITUDE: return "KIND_CHANNEL_ALTITUDE";
689 case KIND_LAND_COVER_MAP: return "KIND_LAND_COVER_MAP";
690 default: return "KIND_UNKNOWN"; ///! Unrecognized object
694 void HYDROData_Entity::setPythonReferenceObject( const QString& thePyScriptPath,
695 MapOfTreatedObjects& theTreatedObjects,
696 QStringList& theScript,
697 const Handle(HYDROData_Entity)& theRefObject,
698 const QString& theMethod ) const
700 if ( !checkObjectPythonDefinition( thePyScriptPath, theTreatedObjects, theScript, theRefObject ) )
703 QString aRefObjName = theRefObject->GetObjPyName();
705 QString anObjName = GetObjPyName();
706 theScript << QString( "%1.%2( %3 )" )
707 .arg( anObjName ).arg( theMethod ).arg( aRefObjName );
710 bool HYDROData_Entity::checkObjectPythonDefinition( const QString& thePyScriptPath,
711 MapOfTreatedObjects& theTreatedObjects,
712 QStringList& theScript,
713 const Handle(HYDROData_Entity)& theRefObject ) const
715 if ( theRefObject.IsNull() )
718 QString aRefObjName = theRefObject->GetName();
719 if ( aRefObjName.isEmpty() )
722 if ( theTreatedObjects.contains( aRefObjName ) )
725 // The definition of reference object must be dumped before this
726 QStringList aRefObjDump = theRefObject->DumpToPython( thePyScriptPath, theTreatedObjects );
727 if ( aRefObjDump.isEmpty() )
730 QStringList aTmpList = theScript;
731 theScript = aRefObjDump;
733 theScript << QString( "" );
734 theScript << aTmpList;
736 theTreatedObjects.insert( aRefObjName, theRefObject );
741 void HYDROData_Entity::setPythonObjectColor( QStringList& theScript,
742 const QColor& theColor,
743 const QColor& theDefaultColor,
744 const QString& theMethod ) const
746 if ( theColor == theDefaultColor )
747 return; //Do not set the color for object if it like default
749 QString anObjName = GetObjPyName();
750 theScript << QString( "%1.%2( QColor( %3, %4, %5, %6 ) )" )
751 .arg( anObjName ).arg( theMethod )
752 .arg( theColor.red() ).arg( theColor.green() )
753 .arg( theColor.blue() ).arg( theColor.alpha() );
756 void HYDROData_Entity::findPythonReferenceObject( QStringList& theScript,
757 QString defName) const
759 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
760 if ( aDocument.IsNull() )
763 if (defName.isEmpty())
764 theScript << QString( "%1 = %2.FindObjectByName( \"%3\" )" ).arg( GetObjPyName() )
765 .arg( aDocument->GetDocPyName() )
766 .arg( GetDefaultName() );
768 theScript << QString( "%1 = %2.FindObjectByName( \"%3\" )" ).arg( GetObjPyName() )
769 .arg( aDocument->GetDocPyName() )
773 void HYDROData_Entity::SetNameInDumpPython(QStringList& theScript,
774 QString theName) const
776 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
777 if ( aDocument.IsNull() )
780 if (theName.isEmpty())
781 theScript << QString( "%1.SetName( \"%2\" )" ).arg( GetObjPyName() )
784 theScript << QString( "%1.SetName( \"%2\" )" ).arg( GetObjPyName() )
788 void HYDROData_Entity::SetShape( int theTag, const TopoDS_Shape& theShape )
790 TNaming_Builder aBuilder( myLab.FindChild( theTag ) );
791 aBuilder.Generated( theShape );
794 TopoDS_Shape HYDROData_Entity::GetShape( int theTag ) const
796 TDF_Label aShapeLabel = myLab.FindChild( theTag, false );
797 if ( !aShapeLabel.IsNull() )
799 Handle(TNaming_NamedShape) aNamedShape;
800 if ( aShapeLabel.FindAttribute( TNaming_NamedShape::GetID(), aNamedShape ) )
801 return aNamedShape->Get();
803 return TopoDS_Shape();
806 void HYDROData_Entity::SetDouble( int theTag, double theValue )
808 Handle(TDataStd_Real) anAttr;
809 TDF_Label aLabel = myLab.FindChild( theTag );
810 if( !aLabel.FindAttribute( TDataStd_Real::GetID(), anAttr ) )
811 aLabel.AddAttribute( anAttr = new TDataStd_Real() );
812 anAttr->Set( theValue );
815 double HYDROData_Entity::GetDouble( int theTag, double theDefValue ) const
817 Handle(TDataStd_Real) anAttr;
818 TDF_Label aLabel = myLab.FindChild( theTag );
819 if( !aLabel.FindAttribute( TDataStd_Real::GetID(), anAttr ) )
822 return anAttr->Get();
825 void HYDROData_Entity::SetInteger( int theTag, int theValue )
827 Handle(TDataStd_Integer) anAttr;
828 TDF_Label aLabel = myLab.FindChild( theTag );
829 if( !aLabel.FindAttribute( TDataStd_Integer::GetID(), anAttr ) )
830 aLabel.AddAttribute( anAttr = new TDataStd_Integer() );
831 anAttr->Set( theValue );
834 int HYDROData_Entity::GetInteger( int theTag, int theDefValue ) const
836 Handle(TDataStd_Integer) anAttr;
837 TDF_Label aLabel = myLab.FindChild( theTag );
838 if( !aLabel.FindAttribute( TDataStd_Integer::GetID(), anAttr ) )
841 return anAttr->Get();