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 Handle(TDataStd_Name) A = TDataStd_Name::Set(myLab, TCollection_ExtendedString(theName.toLatin1().constData()));
109 A->SetID(TDataStd_Name::GetID());
112 TDF_Label aDefaultNameLabel = myLab.FindChild( DataTag_DefaultName, true );
113 if ( aDefaultNameLabel.IsNull() )
115 Handle(TDataStd_AsciiString) theDefaultName;
117 if ( !aDefaultNameLabel.FindAttribute( TDataStd_AsciiString::GetID(), theDefaultName ))
119 TCollection_AsciiString aName = theName.toStdString().c_str();
120 theDefaultName = TDataStd_AsciiString::Set(myLab.FindChild( DataTag_DefaultName), aName );
121 theDefaultName->SetID( TDataStd_AsciiString::GetID() );
126 QStringList HYDROData_Entity::DumpToPython( const QString& thePyScriptPath,
127 MapOfTreatedObjects& theTreatedObjects ) const
129 QStringList anEmptyList;
133 void HYDROData_Entity::Update()
138 void HYDROData_Entity::UpdateLocalCS( double theDx, double theDy )
140 //On the base level no actions are necessary
143 bool HYDROData_Entity::IsHas2dPrs() const
148 void HYDROData_Entity::Show()
153 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
154 if ( aDocument.IsNull() )
157 aDocument->Show( this );
160 QVariant HYDROData_Entity::GetDataVariant()
165 void HYDROData_Entity::ClearChanged()
167 Handle(TDataStd_Integer) A = TDataStd_Integer::Set( myLab.FindChild( DataTag_GeomChange ), 0 );
168 A->SetID(TDataStd_Integer::GetID());
171 int HYDROData_Entity::GetGeomChangeFlag() const
173 int aGeomChangeFlag = 0;
174 Handle(TDataStd_Integer) aGeomChangeAttr;
175 TDF_Label aGeomChangeLab = myLab.FindChild( DataTag_GeomChange );
176 aGeomChangeLab.FindAttribute( TDataStd_Integer::GetID(), aGeomChangeAttr );
177 if ( !aGeomChangeAttr.IsNull() )
178 aGeomChangeFlag = aGeomChangeAttr->Get();
179 return aGeomChangeFlag;
182 void HYDROData_Entity::Changed( Geometry theChangedGeometry )
184 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
185 if( aDocument.IsNull() )
188 int aGeomChangeFlag = 0;
189 Handle(TDataStd_Integer) aGeomChangeAttr;
190 TDF_Label aGeomChangeLab = myLab.FindChild( DataTag_GeomChange );
191 aGeomChangeLab.FindAttribute( TDataStd_Integer::GetID(), aGeomChangeAttr );
192 if ( !aGeomChangeAttr.IsNull() )
193 aGeomChangeFlag = aGeomChangeAttr->Get();
195 int aBitsToChange = ( myGeom & theChangedGeometry );
196 if( aBitsToChange == 0 )
199 aGeomChangeFlag = ( aGeomChangeFlag | aBitsToChange );
200 Handle(TDataStd_Integer) anAttr = TDataStd_Integer::Set( aGeomChangeLab, aGeomChangeFlag );
201 anAttr->SetID( TDataStd_Integer::GetID() );
203 HYDROData_Iterator anIter( aDocument );
204 for ( ; anIter.More(); anIter.Next() )
206 Handle(HYDROData_Entity) anObject = anIter.Current();
207 if( anObject.IsNull() )
209 HYDROData_SequenceOfObjects aRefSeq = anObject->GetAllReferenceObjects();
210 for ( int i = 1, n = aRefSeq.Length(); i <= n; ++i )
212 Handle(HYDROData_Entity) aRefObject = aRefSeq.Value( i );
213 if( aRefObject->Label()==myLab )
214 anObject->Changed( theChangedGeometry );
219 bool HYDROData_Entity::IsMustBeUpdated( Geometry theGeom ) const
221 return ( ( GetGeomChangeFlag() & theGeom ) != 0 );
224 bool HYDROData_Entity::CanBeUpdated() const
229 bool HYDROData_Entity::IsRemoved() const
231 return !myLab.HasAttribute();
234 void HYDROData_Entity::Remove()
236 return myLab.ForgetAllAttributes( true );
239 bool HYDROData_Entity::CanRemove()
244 HYDROData_Entity::HYDROData_Entity( Geometry theGeom )
249 HYDROData_Entity::~HYDROData_Entity()
253 void HYDROData_Entity::CopyTo( const Handle(HYDROData_Entity)& theDestination,
254 bool isGenerateNewName ) const
256 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
257 if ( aDocument.IsNull() ) {
261 TDF_CopyLabel aCopy(myLab, theDestination->Label());
264 if( isGenerateNewName )
266 // generate a new unique name for the clone object:
267 // case 1: Image_1 -> Image_2
268 // case 2: ImageObj -> ImageObj_1
269 QString aName = theDestination->GetName();
270 QString aPrefix = aName;
271 if( aName.contains( '_' ) ) { // case 1
272 QString aSuffix = aName.section( '_', -1 );
273 bool anIsInteger = false;
274 aSuffix.toInt( &anIsInteger );
276 aPrefix = aName.section( '_', 0, -2 );
281 aName = HYDROData_Tool::GenerateObjectName( aDocument, aPrefix );
282 theDestination->SetName( aName );
286 Handle(HYDROData_Entity) HYDROData_Entity::GetFatherObject() const
288 Handle(HYDROData_Entity) aFather;
290 if ( !myLab.IsNull() )
292 TDF_Label aFatherLabel = myLab.Father();
294 while ( aFather.IsNull() && !aFatherLabel.IsNull() && !aFatherLabel.IsRoot() )
296 aFather = HYDROData_Iterator::Object( aFatherLabel );
297 aFatherLabel = aFatherLabel.Father();
304 HYDROData_SequenceOfObjects HYDROData_Entity::GetAllReferenceObjects() const
306 return HYDROData_SequenceOfObjects();
309 bool HYDROData_Entity::GetZLevel( Standard_Integer& theLevel ) const
313 TDF_Label aLabel = myLab.FindChild( DataTag_ZLevel, false );
314 if ( !aLabel.IsNull() )
316 Handle(TDataStd_Integer) anIntVal;
317 if ( aLabel.FindAttribute( TDataStd_Integer::GetID(), anIntVal ) )
319 theLevel = anIntVal->Get();
327 void HYDROData_Entity::SetZLevel( const Standard_Integer& theLevel )
329 Handle(TDataStd_Integer) A = TDataStd_Integer::Set( myLab.FindChild( DataTag_ZLevel ), theLevel );
330 A->SetID(TDataStd_Integer::GetID());
333 void HYDROData_Entity::RemoveZLevel()
335 TDF_Label aLabel = myLab.FindChild( DataTag_ZLevel, false );
336 if ( !aLabel.IsNull() )
337 aLabel.ForgetAllAttributes();
340 void HYDROData_Entity::SetLabel( const TDF_Label& theLabel )
345 void HYDROData_Entity::SaveByteArray( const int theTag,
349 TDF_Label aLab = theTag == 0 ? myLab : myLab.FindChild(theTag);
350 // array is empty, remove the attribute
352 aLab.ForgetAttribute(TDataStd_ByteArray::GetID());
355 // store data of image in byte array
356 Handle(TDataStd_ByteArray) aData;
357 if (!aLab.FindAttribute(TDataStd_ByteArray::GetID(), aData)) {
358 aData = TDataStd_ByteArray::Set(aLab, 1, theLen);
359 aData->SetID( TDataStd_ByteArray::GetID() );
361 Standard_Byte* Byte0 = &(aData->InternalArray()->ChangeArray1().ChangeFirst());
362 memcpy(Byte0, theData, theLen * sizeof (char));
363 // copy bytes one by one
364 if (aData->Length() != theLen) {
365 Handle(TColStd_HArray1OfByte) aNewData = new TColStd_HArray1OfByte(1, theLen);
366 for(int a = 0; a < theLen; a++)
367 aNewData->SetValue(a + 1, theData[a]);
368 aData->ChangeArray(aNewData);
372 // for(int a = 0; a < theLen; a++)
373 // aData->SetValue(a + 1, theData[a]);
377 const char* HYDROData_Entity::ByteArray(const int theTag, int& theLen) const
379 TDF_Label aLab = theTag == 0 ? myLab : myLab.FindChild(theTag);
380 Handle(TDataStd_ByteArray) aData;
381 if (!aLab.FindAttribute(TDataStd_ByteArray::GetID(), aData))
382 return NULL; // return empty image if there is no array
383 theLen = aData->Length();
385 return (const char*)(&(aData->InternalArray()->ChangeArray1().ChangeValue(1)));
389 int HYDROData_Entity::NbReferenceObjects( const int theTag ) const
391 Handle(TDataStd_ReferenceList) aRefs = getReferenceList( theTag, false );
392 return aRefs.IsNull() ? 0 : aRefs->Extent();
395 bool HYDROData_Entity::HasReference( const Handle(HYDROData_Entity)& theObj,
396 const int theTag ) const
398 if ( theObj.IsNull() )
401 Handle(TDataStd_ReferenceList) aRefs = getReferenceList( theTag, false );
402 if ( aRefs.IsNull() || aRefs->IsEmpty() )
405 TDF_ListIteratorOfLabelList aListIt( aRefs->List() );
406 for ( ; aListIt.More(); aListIt.Next() )
408 const TDF_Label& aRefLabel = aListIt.Value();
409 if ( theObj->Label() == aRefLabel )
416 void HYDROData_Entity::AddReferenceObject( const Handle(HYDROData_Entity)& theObj,
419 if ( theObj.IsNull() )
422 Handle(TDataStd_ReferenceList) aRefs = getReferenceList( theTag, true );
423 aRefs->Append( theObj->Label() );
424 aRefs->SetID(TDataStd_ReferenceList::GetID());
427 void HYDROData_Entity::SetReferenceObject( const Handle(HYDROData_Entity)& theObj,
431 if ( theObj.IsNull() )
433 RemoveReferenceObject( theTag, theIndex );
437 Handle(TDataStd_ReferenceList) aRefs = getReferenceList( theTag, true );
439 if ( theIndex >= aRefs->Extent() )
441 aRefs->Append( theObj->Label() );
443 else if ( theIndex < 0 )
445 aRefs->Prepend( theObj->Label() );
449 RemoveReferenceObject( theTag, theIndex );
451 Handle(HYDROData_Entity) aBeforeObj = GetReferenceObject( theTag, theIndex );
453 aRefs = getReferenceList( theTag, true ); // because reference list can be removed
454 if ( !aBeforeObj.IsNull() )
455 aRefs->InsertBefore( theObj->Label(), aBeforeObj->Label() );
457 aRefs->Append( theObj->Label() );
461 void HYDROData_Entity::InsertReferenceObject( const Handle(HYDROData_Entity)& theObj,
463 const int theBeforeIndex )
465 if ( theObj.IsNull() )
468 Handle(TDataStd_ReferenceList) aRefs = getReferenceList( theTag, true );
470 if ( theBeforeIndex >= aRefs->Extent() )
472 aRefs->Append( theObj->Label() );
474 else if ( theBeforeIndex < 0 )
476 aRefs->Prepend( theObj->Label() );
480 Handle(HYDROData_Entity) aBeforeObj = GetReferenceObject( theTag, theBeforeIndex );
481 if ( !aBeforeObj.IsNull() )
482 aRefs->InsertBefore( theObj->Label(), aBeforeObj->Label() );
484 aRefs->Append( theObj->Label() );
488 void HYDROData_Entity::SetReferenceObjects( const HYDROData_SequenceOfObjects& theObjects,
491 ClearReferenceObjects( theTag );
492 if ( theObjects.IsEmpty() )
495 HYDROData_SequenceOfObjects::Iterator anIter( theObjects );
496 for ( ; anIter.More(); anIter.Next() )
497 AddReferenceObject( anIter.Value(), theTag );
500 Handle(HYDROData_Entity) HYDROData_Entity::GetReferenceObject( const int theTag,
501 const int theIndex ) const
503 //DEBTRACE("GetReferenceObject " << theTag << " " << theIndex);
504 Handle(HYDROData_Entity) aRes;
506 Handle(TDataStd_ReferenceList) aRefs = getReferenceList( theTag, false );
507 if ( aRefs.IsNull() || theIndex < 0 || theIndex >= aRefs->Extent() )
510 TDF_ListIteratorOfLabelList anIter( aRefs->List() );
511 for ( int anIndex = 0; anIndex != theIndex && anIter.More(); anIter.Next(), ++anIndex );
513 const TDF_Label& aRefLabel = anIter.Value();
514 aRes = HYDROData_Iterator::Object( aRefLabel );
519 HYDROData_SequenceOfObjects HYDROData_Entity::GetReferenceObjects( const int theTag ) const
521 HYDROData_SequenceOfObjects aRes;
523 Handle(TDataStd_ReferenceList) aRefs = getReferenceList( theTag, false );
524 if ( aRefs.IsNull() )
527 TDF_ListIteratorOfLabelList anIter( aRefs->List() );
528 for ( ; anIter.More(); anIter.Next() )
530 const TDF_Label& aRefLabel = anIter.Value();
532 Handle(HYDROData_Entity) aRefObject = HYDROData_Iterator::Object( aRefLabel );
533 if ( aRefObject.IsNull() )
536 aRes.Append( aRefObject );
542 void HYDROData_Entity::RemoveReferenceObject( const TDF_Label& theRefLabel,
545 Handle(TDataStd_ReferenceList) aRefs = getReferenceList( theTag, false );
546 if ( aRefs.IsNull() )
549 if ( aRefs->Extent() == 1 )
551 // remove all if only one
552 ClearReferenceObjects( theTag );
556 aRefs->Remove( theRefLabel );
559 void HYDROData_Entity::RemoveReferenceObject( const int theTag,
562 Handle(TDataStd_ReferenceList) aRefs = getReferenceList( theTag, false );
563 if ( aRefs.IsNull() )
566 if ( aRefs->Extent() == 1 && theIndex == 0 )
568 // remove all if only one
569 ClearReferenceObjects( theTag );
574 TDF_ListIteratorOfLabelList anIter( aRefs->List() );
575 for ( ; anIndex != theIndex && anIter.More(); anIter.Next(), ++anIndex );
577 if ( anIndex != theIndex || !anIter.More() )
580 const TDF_Label& aRefLabel = anIter.Value();
581 aRefs->Remove( aRefLabel );
584 void HYDROData_Entity::ClearReferenceObjects( const int theTag )
586 TDF_Label aSetLabel = theTag == 0 ? myLab : myLab.FindChild( theTag );
587 aSetLabel.ForgetAttribute( TDataStd_ReferenceList::GetID() );
590 Handle(TDataStd_ReferenceList) HYDROData_Entity::getReferenceList( const int theTag,
591 const bool theIsCreate ) const
593 //DEBTRACE("getReferenceList " << theTag << " " << theIsCreate);
594 TDF_Label aLabel = theTag == 0 ? myLab : myLab.FindChild( theTag );
596 Handle(TDataStd_ReferenceList) aRefs;
597 if ( !aLabel.FindAttribute( TDataStd_ReferenceList::GetID(), aRefs ) && theIsCreate )
599 aRefs = TDataStd_ReferenceList::Set( aLabel );
600 aRefs->SetID(TDataStd_ReferenceList::GetID());
605 void HYDROData_Entity::SetColor( const QColor& theColor,
608 TDF_Label aLabel = theTag == 0 ? myLab : myLab.FindChild( theTag );
610 Handle(TDataStd_IntegerArray) aColorArray;
611 if ( !aLabel.FindAttribute( TDataStd_IntegerArray::GetID(), aColorArray ) )
613 aColorArray = TDataStd_IntegerArray::Set( aLabel, 1, 4 );
614 aColorArray->SetID(TDataStd_IntegerArray::GetID());
617 aColorArray->SetValue( 1, theColor.red() );
618 aColorArray->SetValue( 2, theColor.green() );
619 aColorArray->SetValue( 3, theColor.blue() );
620 aColorArray->SetValue( 4, theColor.alpha() );
623 QColor HYDROData_Entity::GetColor( const QColor& theDefColor,
624 const int theTag ) const
626 QColor aResColor = theDefColor;
628 TDF_Label aLabel = theTag == 0 ? myLab : myLab.FindChild( theTag );
630 Handle(TDataStd_IntegerArray) aColorArray;
631 if ( aLabel.FindAttribute( TDataStd_IntegerArray::GetID(), aColorArray ) )
633 aResColor.setRed( aColorArray->Value( 1 ) );
634 aResColor.setGreen( aColorArray->Value( 2 ) );
635 aResColor.setBlue( aColorArray->Value( 3 ) );
636 aResColor.setAlpha( aColorArray->Value( 4 ) );
642 QStringList HYDROData_Entity::dumpObjectCreation( MapOfTreatedObjects& theTreatedObjects ) const
644 QStringList aResList;
646 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
647 if ( aDocument.IsNull() )
650 QString aDocName = aDocument->GetDocPyName();
651 QString aName = GetObjPyName();
653 aResList << QString( "%1 = %2.CreateObject( %3 )" )
654 .arg( aName ).arg( aDocName ).arg( getPyTypeID() );
655 aResList << QString( "%1.SetName( \"%2\" )" )
656 .arg( aName ).arg( GetName() );
657 aResList << QString( "" );
661 // Dump object z-level in viewer
662 Standard_Integer anObjZLevel = -1;
663 if ( GetZLevel( anObjZLevel ) )
665 aResList << QString( "%1.SetZLevel( %2 )" )
666 .arg( aName ).arg( anObjZLevel );
667 aResList << QString( "" );
674 QString HYDROData_Entity::getPyTypeID() const
676 //DEBTRACE("HYDROData_Entity::getPyTypeID " << GetKind());
679 case KIND_IMAGE: return "KIND_IMAGE";
680 case KIND_POLYLINE: return "KIND_POLYLINE";
681 case KIND_BATHYMETRY: return "KIND_BATHYMETRY";
682 case KIND_ALTITUDE: return "KIND_ALTITUDE";
683 case KIND_IMMERSIBLE_ZONE: return "KIND_IMMERSIBLE_ZONE";
684 case KIND_RIVER: return "KIND_RIVER";
685 case KIND_STREAM: return "KIND_STREAM";
686 case KIND_CONFLUENCE: return "KIND_CONFLUENCE";
687 case KIND_CHANNEL: return "KIND_CHANNEL";
688 case KIND_OBSTACLE: return "KIND_OBSTACLE";
689 case KIND_DIGUE: return "KIND_DIGUE";
690 case KIND_PROFILE: return "KIND_PROFILE";
691 case KIND_PROFILEUZ: return "KIND_PROFILEUZ";
692 case KIND_POLYLINEXY: return "KIND_POLYLINEXY";
693 case KIND_CALCULATION: return "KIND_CALCULATION";
694 case KIND_ZONE: return "KIND_ZONE";
695 case KIND_REGION: return "KIND_REGION";
696 case KIND_VISUAL_STATE: return "KIND_VISUAL_STATE";
697 case KIND_ARTIFICIAL_OBJECT: return "KIND_ARTIFICIAL_OBJECT";
698 case KIND_NATURAL_OBJECT: return "KIND_NATURAL_OBJECT";
699 case KIND_DUMMY_3D: return "KIND_DUMMY_3D";
700 case KIND_SHAPES_GROUP: return "KIND_SHAPES_GROUP";
701 case KIND_SPLIT_GROUP: return "KIND_SPLIT_GROUP";
702 case KIND_STREAM_ALTITUDE: return "KIND_STREAM_ALTITUDE";
703 case KIND_OBSTACLE_ALTITUDE: return "KIND_OBSTACLE_ALTITUDE";
704 case KIND_STRICKLER_TABLE: return "KIND_STRICKLER_TABLE";
705 case KIND_LAND_COVER_OBSOLETE: return "";
706 case KIND_CHANNEL_ALTITUDE: return "KIND_CHANNEL_ALTITUDE";
707 case KIND_LAND_COVER_MAP: return "KIND_LAND_COVER_MAP";
708 default: return "KIND_UNKNOWN"; ///! Unrecognized object
712 void HYDROData_Entity::setPythonReferenceObject( const QString& thePyScriptPath,
713 MapOfTreatedObjects& theTreatedObjects,
714 QStringList& theScript,
715 const Handle(HYDROData_Entity)& theRefObject,
716 const QString& theMethod ) const
718 if ( !checkObjectPythonDefinition( thePyScriptPath, theTreatedObjects, theScript, theRefObject ) )
721 QString aRefObjName = theRefObject->GetObjPyName();
723 QString anObjName = GetObjPyName();
724 theScript << QString( "%1.%2( %3 )" )
725 .arg( anObjName ).arg( theMethod ).arg( aRefObjName );
728 bool HYDROData_Entity::checkObjectPythonDefinition( const QString& thePyScriptPath,
729 MapOfTreatedObjects& theTreatedObjects,
730 QStringList& theScript,
731 const Handle(HYDROData_Entity)& theRefObject ) const
733 if ( theRefObject.IsNull() )
736 QString aRefObjName = theRefObject->GetName();
737 if ( aRefObjName.isEmpty() )
740 if ( theTreatedObjects.contains( aRefObjName ) )
743 // The definition of reference object must be dumped before this
744 QStringList aRefObjDump = theRefObject->DumpToPython( thePyScriptPath, theTreatedObjects );
745 if ( aRefObjDump.isEmpty() )
748 QStringList aTmpList = theScript;
749 theScript = aRefObjDump;
751 theScript << QString( "" );
752 theScript << aTmpList;
754 theTreatedObjects.insert( aRefObjName, theRefObject );
759 void HYDROData_Entity::setPythonObjectColor( QStringList& theScript,
760 const QColor& theColor,
761 const QColor& theDefaultColor,
762 const QString& theMethod ) const
764 if ( theColor == theDefaultColor )
765 return; //Do not set the color for object if it like default
767 QString anObjName = GetObjPyName();
768 theScript << QString( "%1.%2( QColor( %3, %4, %5, %6 ) )" )
769 .arg( anObjName ).arg( theMethod )
770 .arg( theColor.red() ).arg( theColor.green() )
771 .arg( theColor.blue() ).arg( theColor.alpha() );
774 void HYDROData_Entity::findPythonReferenceObject( QStringList& theScript,
775 QString defName) const
777 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
778 if ( aDocument.IsNull() )
781 if (defName.isEmpty())
782 theScript << QString( "%1 = %2.FindObjectByName( \"%3\" )" ).arg( GetObjPyName() )
783 .arg( aDocument->GetDocPyName() )
784 .arg( GetDefaultName() );
786 theScript << QString( "%1 = %2.FindObjectByName( \"%3\" )" ).arg( GetObjPyName() )
787 .arg( aDocument->GetDocPyName() )
791 void HYDROData_Entity::SetNameInDumpPython(QStringList& theScript,
792 QString theName) const
794 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
795 if ( aDocument.IsNull() )
798 if (theName.isEmpty())
799 theScript << QString( "%1.SetName( \"%2\" )" ).arg( GetObjPyName() )
802 theScript << QString( "%1.SetName( \"%2\" )" ).arg( GetObjPyName() )
806 void HYDROData_Entity::SetShape( int theTag, const TopoDS_Shape& theShape )
808 TNaming_Builder aBuilder( myLab.FindChild( theTag ) );
809 aBuilder.Generated( theShape );
810 aBuilder.NamedShape()->SetID(TNaming_NamedShape::GetID());
813 TopoDS_Shape HYDROData_Entity::GetShape( int theTag ) const
815 TDF_Label aShapeLabel = myLab.FindChild( theTag, false );
816 if ( !aShapeLabel.IsNull() )
818 Handle(TNaming_NamedShape) aNamedShape;
819 if ( aShapeLabel.FindAttribute( TNaming_NamedShape::GetID(), aNamedShape ) )
820 return aNamedShape->Get();
822 return TopoDS_Shape();
825 void HYDROData_Entity::SetDouble( int theTag, double theValue )
827 Handle(TDataStd_Real) anAttr;
828 TDF_Label aLabel = myLab.FindChild( theTag );
829 if( !aLabel.FindAttribute( TDataStd_Real::GetID(), anAttr ) )
831 anAttr = new TDataStd_Real();
832 anAttr->SetID(TDataStd_Real::GetID());
833 aLabel.AddAttribute( anAttr );
835 anAttr->Set( theValue );
838 double HYDROData_Entity::GetDouble( int theTag, double theDefValue ) const
840 Handle(TDataStd_Real) anAttr;
841 TDF_Label aLabel = myLab.FindChild( theTag );
842 if( !aLabel.FindAttribute( TDataStd_Real::GetID(), anAttr ) )
845 return anAttr->Get();
848 void HYDROData_Entity::SetInteger( int theTag, int theValue )
850 Handle(TDataStd_Integer) anAttr;
851 TDF_Label aLabel = myLab.FindChild( theTag );
852 if( !aLabel.FindAttribute( TDataStd_Integer::GetID(), anAttr ) )
854 anAttr = new TDataStd_Integer();
855 anAttr->SetID(TDataStd_Integer::GetID());
856 aLabel.AddAttribute(anAttr);
858 anAttr->Set( theValue );
861 int HYDROData_Entity::GetInteger( int theTag, int theDefValue ) const
863 Handle(TDataStd_Integer) anAttr;
864 TDF_Label aLabel = myLab.FindChild( theTag );
865 if( !aLabel.FindAttribute( TDataStd_Integer::GetID(), anAttr ) )
868 return anAttr->Get();
871 bool HYDROData_Entity::CompareLabels(const Handle(HYDROData_Entity)& theOtherObj)
873 if ( !theOtherObj.IsNull() )
874 return this->Label() == theOtherObj->Label();