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 );
120 theDefaultName->SetID( TDataStd_AsciiString::GetID() );
125 QStringList HYDROData_Entity::DumpToPython( const QString& thePyScriptPath,
126 MapOfTreatedObjects& theTreatedObjects ) const
128 QStringList anEmptyList;
132 void HYDROData_Entity::Update()
137 void HYDROData_Entity::UpdateLocalCS( double theDx, double theDy )
139 //On the base level no actions are necessary
142 bool HYDROData_Entity::IsHas2dPrs() const
147 void HYDROData_Entity::Show()
152 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
153 if ( aDocument.IsNull() )
156 aDocument->Show( this );
159 QVariant HYDROData_Entity::GetDataVariant()
164 void HYDROData_Entity::ClearChanged()
166 TDataStd_Integer::Set( myLab.FindChild( DataTag_GeomChange ), 0 );
169 int HYDROData_Entity::GetGeomChangeFlag() const
171 int aGeomChangeFlag = 0;
172 Handle(TDataStd_Integer) aGeomChangeAttr;
173 TDF_Label aGeomChangeLab = myLab.FindChild( DataTag_GeomChange );
174 aGeomChangeLab.FindAttribute( TDataStd_Integer::GetID(), aGeomChangeAttr );
175 if ( !aGeomChangeAttr.IsNull() )
176 aGeomChangeFlag = aGeomChangeAttr->Get();
177 return aGeomChangeFlag;
180 void HYDROData_Entity::Changed( Geometry theChangedGeometry )
182 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
183 if( aDocument.IsNull() )
186 int aGeomChangeFlag = 0;
187 Handle(TDataStd_Integer) aGeomChangeAttr;
188 TDF_Label aGeomChangeLab = myLab.FindChild( DataTag_GeomChange );
189 aGeomChangeLab.FindAttribute( TDataStd_Integer::GetID(), aGeomChangeAttr );
190 if ( !aGeomChangeAttr.IsNull() )
191 aGeomChangeFlag = aGeomChangeAttr->Get();
193 int aBitsToChange = ( myGeom & theChangedGeometry );
194 if( aBitsToChange == 0 )
197 aGeomChangeFlag = ( aGeomChangeFlag | aBitsToChange );
198 Handle(TDataStd_Integer) anAttr = TDataStd_Integer::Set( aGeomChangeLab, aGeomChangeFlag );
199 anAttr->SetID( TDataStd_Integer::GetID() );
201 HYDROData_Iterator anIter( aDocument );
202 for ( ; anIter.More(); anIter.Next() )
204 Handle(HYDROData_Entity) anObject = anIter.Current();
205 if( anObject.IsNull() )
207 HYDROData_SequenceOfObjects aRefSeq = anObject->GetAllReferenceObjects();
208 for ( int i = 1, n = aRefSeq.Length(); i <= n; ++i )
210 Handle(HYDROData_Entity) aRefObject = aRefSeq.Value( i );
211 if( aRefObject->Label()==myLab )
212 anObject->Changed( theChangedGeometry );
217 bool HYDROData_Entity::IsMustBeUpdated( Geometry theGeom ) const
219 return ( ( GetGeomChangeFlag() & theGeom ) != 0 );
222 bool HYDROData_Entity::CanBeUpdated() const
227 bool HYDROData_Entity::IsRemoved() const
229 return !myLab.HasAttribute();
232 void HYDROData_Entity::Remove()
234 return myLab.ForgetAllAttributes( true );
237 bool HYDROData_Entity::CanRemove()
242 HYDROData_Entity::HYDROData_Entity( Geometry theGeom )
247 HYDROData_Entity::~HYDROData_Entity()
251 void HYDROData_Entity::CopyTo( const Handle(HYDROData_Entity)& theDestination,
252 bool isGenerateNewName ) const
254 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
255 if ( aDocument.IsNull() ) {
259 TDF_CopyLabel aCopy(myLab, theDestination->Label());
262 if( isGenerateNewName )
264 // generate a new unique name for the clone object:
265 // case 1: Image_1 -> Image_2
266 // case 2: ImageObj -> ImageObj_1
267 QString aName = theDestination->GetName();
268 QString aPrefix = aName;
269 if( aName.contains( '_' ) ) { // case 1
270 QString aSuffix = aName.section( '_', -1 );
271 bool anIsInteger = false;
272 aSuffix.toInt( &anIsInteger );
274 aPrefix = aName.section( '_', 0, -2 );
279 aName = HYDROData_Tool::GenerateObjectName( aDocument, aPrefix );
280 theDestination->SetName( aName );
284 Handle(HYDROData_Entity) HYDROData_Entity::GetFatherObject() const
286 Handle(HYDROData_Entity) aFather;
288 if ( !myLab.IsNull() )
290 TDF_Label aFatherLabel = myLab.Father();
292 while ( aFather.IsNull() && !aFatherLabel.IsNull() && !aFatherLabel.IsRoot() )
294 aFather = HYDROData_Iterator::Object( aFatherLabel );
295 aFatherLabel = aFatherLabel.Father();
302 HYDROData_SequenceOfObjects HYDROData_Entity::GetAllReferenceObjects() const
304 return HYDROData_SequenceOfObjects();
307 bool HYDROData_Entity::GetZLevel( Standard_Integer& theLevel ) const
311 TDF_Label aLabel = myLab.FindChild( DataTag_ZLevel, false );
312 if ( !aLabel.IsNull() )
314 Handle(TDataStd_Integer) anIntVal;
315 if ( aLabel.FindAttribute( TDataStd_Integer::GetID(), anIntVal ) )
317 theLevel = anIntVal->Get();
325 void HYDROData_Entity::SetZLevel( const Standard_Integer& theLevel )
327 TDataStd_Integer::Set( myLab.FindChild( DataTag_ZLevel ), theLevel );
330 void HYDROData_Entity::RemoveZLevel()
332 TDF_Label aLabel = myLab.FindChild( DataTag_ZLevel, false );
333 if ( !aLabel.IsNull() )
334 aLabel.ForgetAllAttributes();
337 void HYDROData_Entity::SetLabel( const TDF_Label& theLabel )
342 void HYDROData_Entity::SaveByteArray( const int theTag,
346 TDF_Label aLab = theTag == 0 ? myLab : myLab.FindChild(theTag);
347 // array is empty, remove the attribute
349 aLab.ForgetAttribute(TDataStd_ByteArray::GetID());
352 // store data of image in byte array
353 Handle(TDataStd_ByteArray) aData;
354 if (!aLab.FindAttribute(TDataStd_ByteArray::GetID(), aData)) {
355 aData = TDataStd_ByteArray::Set(aLab, 1, theLen);
356 aData->SetID( TDataStd_ByteArray::GetID() );
358 Standard_Byte* Byte0 = &(aData->InternalArray()->ChangeArray1().ChangeFirst());
359 memcpy(Byte0, theData, theLen * sizeof (char));
360 // copy bytes one by one
361 if (aData->Length() != theLen) {
362 Handle(TColStd_HArray1OfByte) aNewData = new TColStd_HArray1OfByte(1, theLen);
363 for(int a = 0; a < theLen; a++)
364 aNewData->SetValue(a + 1, theData[a]);
365 aData->ChangeArray(aNewData);
369 // for(int a = 0; a < theLen; a++)
370 // aData->SetValue(a + 1, theData[a]);
374 const char* HYDROData_Entity::ByteArray(const int theTag, int& theLen) const
376 TDF_Label aLab = theTag == 0 ? myLab : myLab.FindChild(theTag);
377 Handle(TDataStd_ByteArray) aData;
378 if (!aLab.FindAttribute(TDataStd_ByteArray::GetID(), aData))
379 return NULL; // return empty image if there is no array
380 theLen = aData->Length();
382 return (const char*)(&(aData->InternalArray()->ChangeArray1().ChangeValue(1)));
386 int HYDROData_Entity::NbReferenceObjects( const int theTag ) const
388 Handle(TDataStd_ReferenceList) aRefs = getReferenceList( theTag, false );
389 return aRefs.IsNull() ? 0 : aRefs->Extent();
392 bool HYDROData_Entity::HasReference( const Handle(HYDROData_Entity)& theObj,
393 const int theTag ) const
395 if ( theObj.IsNull() )
398 Handle(TDataStd_ReferenceList) aRefs = getReferenceList( theTag, false );
399 if ( aRefs.IsNull() || aRefs->IsEmpty() )
402 TDF_ListIteratorOfLabelList aListIt( aRefs->List() );
403 for ( ; aListIt.More(); aListIt.Next() )
405 const TDF_Label& aRefLabel = aListIt.Value();
406 if ( theObj->Label() == aRefLabel )
413 void HYDROData_Entity::AddReferenceObject( const Handle(HYDROData_Entity)& theObj,
416 if ( theObj.IsNull() )
419 Handle(TDataStd_ReferenceList) aRefs = getReferenceList( theTag, true );
420 aRefs->Append( theObj->Label() );
423 void HYDROData_Entity::SetReferenceObject( const Handle(HYDROData_Entity)& theObj,
427 if ( theObj.IsNull() )
429 RemoveReferenceObject( theTag, theIndex );
433 Handle(TDataStd_ReferenceList) aRefs = getReferenceList( theTag, true );
435 if ( theIndex >= aRefs->Extent() )
437 aRefs->Append( theObj->Label() );
439 else if ( theIndex < 0 )
441 aRefs->Prepend( theObj->Label() );
445 RemoveReferenceObject( theTag, theIndex );
447 Handle(HYDROData_Entity) aBeforeObj = GetReferenceObject( theTag, theIndex );
449 aRefs = getReferenceList( theTag, true ); // because reference list can be removed
450 if ( !aBeforeObj.IsNull() )
451 aRefs->InsertBefore( theObj->Label(), aBeforeObj->Label() );
453 aRefs->Append( theObj->Label() );
457 void HYDROData_Entity::InsertReferenceObject( const Handle(HYDROData_Entity)& theObj,
459 const int theBeforeIndex )
461 if ( theObj.IsNull() )
464 Handle(TDataStd_ReferenceList) aRefs = getReferenceList( theTag, true );
466 if ( theBeforeIndex >= aRefs->Extent() )
468 aRefs->Append( theObj->Label() );
470 else if ( theBeforeIndex < 0 )
472 aRefs->Prepend( theObj->Label() );
476 Handle(HYDROData_Entity) aBeforeObj = GetReferenceObject( theTag, theBeforeIndex );
477 if ( !aBeforeObj.IsNull() )
478 aRefs->InsertBefore( theObj->Label(), aBeforeObj->Label() );
480 aRefs->Append( theObj->Label() );
484 void HYDROData_Entity::SetReferenceObjects( const HYDROData_SequenceOfObjects& theObjects,
487 ClearReferenceObjects( theTag );
488 if ( theObjects.IsEmpty() )
491 HYDROData_SequenceOfObjects::Iterator anIter( theObjects );
492 for ( ; anIter.More(); anIter.Next() )
493 AddReferenceObject( anIter.Value(), theTag );
496 Handle(HYDROData_Entity) HYDROData_Entity::GetReferenceObject( const int theTag,
497 const int theIndex ) const
499 //DEBTRACE("GetReferenceObject " << theTag << " " << theIndex);
500 Handle(HYDROData_Entity) aRes;
502 Handle(TDataStd_ReferenceList) aRefs = getReferenceList( theTag, false );
503 if ( aRefs.IsNull() || theIndex < 0 || theIndex >= aRefs->Extent() )
506 TDF_ListIteratorOfLabelList anIter( aRefs->List() );
507 for ( int anIndex = 0; anIndex != theIndex && anIter.More(); anIter.Next(), ++anIndex );
509 const TDF_Label& aRefLabel = anIter.Value();
510 aRes = HYDROData_Iterator::Object( aRefLabel );
515 HYDROData_SequenceOfObjects HYDROData_Entity::GetReferenceObjects( const int theTag ) const
517 HYDROData_SequenceOfObjects aRes;
519 Handle(TDataStd_ReferenceList) aRefs = getReferenceList( theTag, false );
520 if ( aRefs.IsNull() )
523 TDF_ListIteratorOfLabelList anIter( aRefs->List() );
524 for ( ; anIter.More(); anIter.Next() )
526 const TDF_Label& aRefLabel = anIter.Value();
528 Handle(HYDROData_Entity) aRefObject = HYDROData_Iterator::Object( aRefLabel );
529 if ( aRefObject.IsNull() )
532 aRes.Append( aRefObject );
538 void HYDROData_Entity::RemoveReferenceObject( const TDF_Label& theRefLabel,
541 Handle(TDataStd_ReferenceList) aRefs = getReferenceList( theTag, false );
542 if ( aRefs.IsNull() )
545 if ( aRefs->Extent() == 1 )
547 // remove all if only one
548 ClearReferenceObjects( theTag );
552 aRefs->Remove( theRefLabel );
555 void HYDROData_Entity::RemoveReferenceObject( const int theTag,
558 Handle(TDataStd_ReferenceList) aRefs = getReferenceList( theTag, false );
559 if ( aRefs.IsNull() )
562 if ( aRefs->Extent() == 1 && theIndex == 0 )
564 // remove all if only one
565 ClearReferenceObjects( theTag );
570 TDF_ListIteratorOfLabelList anIter( aRefs->List() );
571 for ( ; anIndex != theIndex && anIter.More(); anIter.Next(), ++anIndex );
573 if ( anIndex != theIndex || !anIter.More() )
576 const TDF_Label& aRefLabel = anIter.Value();
577 aRefs->Remove( aRefLabel );
580 void HYDROData_Entity::ClearReferenceObjects( const int theTag )
582 TDF_Label aSetLabel = theTag == 0 ? myLab : myLab.FindChild( theTag );
583 aSetLabel.ForgetAttribute( TDataStd_ReferenceList::GetID() );
586 Handle(TDataStd_ReferenceList) HYDROData_Entity::getReferenceList( const int theTag,
587 const bool theIsCreate ) const
589 //DEBTRACE("getReferenceList " << theTag << " " << theIsCreate);
590 TDF_Label aLabel = theTag == 0 ? myLab : myLab.FindChild( theTag );
592 Handle(TDataStd_ReferenceList) aRefs;
593 if ( !aLabel.FindAttribute( TDataStd_ReferenceList::GetID(), aRefs ) && theIsCreate )
595 aRefs = TDataStd_ReferenceList::Set( aLabel );
596 aRefs->SetID(TDataStd_ReferenceList::GetID());
601 void HYDROData_Entity::SetColor( const QColor& theColor,
604 TDF_Label aLabel = theTag == 0 ? myLab : myLab.FindChild( theTag );
606 Handle(TDataStd_IntegerArray) aColorArray;
607 if ( !aLabel.FindAttribute( TDataStd_IntegerArray::GetID(), aColorArray ) )
608 aColorArray = TDataStd_IntegerArray::Set( aLabel, 1, 4 );
610 aColorArray->SetValue( 1, theColor.red() );
611 aColorArray->SetValue( 2, theColor.green() );
612 aColorArray->SetValue( 3, theColor.blue() );
613 aColorArray->SetValue( 4, theColor.alpha() );
616 QColor HYDROData_Entity::GetColor( const QColor& theDefColor,
617 const int theTag ) const
619 QColor aResColor = theDefColor;
621 TDF_Label aLabel = theTag == 0 ? myLab : myLab.FindChild( theTag );
623 Handle(TDataStd_IntegerArray) aColorArray;
624 if ( aLabel.FindAttribute( TDataStd_IntegerArray::GetID(), aColorArray ) )
626 aResColor.setRed( aColorArray->Value( 1 ) );
627 aResColor.setGreen( aColorArray->Value( 2 ) );
628 aResColor.setBlue( aColorArray->Value( 3 ) );
629 aResColor.setAlpha( aColorArray->Value( 4 ) );
635 QStringList HYDROData_Entity::dumpObjectCreation( MapOfTreatedObjects& theTreatedObjects ) const
637 QStringList aResList;
639 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
640 if ( aDocument.IsNull() )
643 QString aDocName = aDocument->GetDocPyName();
644 QString aName = GetObjPyName();
646 aResList << QString( "%1 = %2.CreateObject( %3 )" )
647 .arg( aName ).arg( aDocName ).arg( getPyTypeID() );
648 aResList << QString( "%1.SetName( \"%2\" )" )
649 .arg( aName ).arg( GetName() );
650 aResList << QString( "" );
654 // Dump object z-level in viewer
655 Standard_Integer anObjZLevel = -1;
656 if ( GetZLevel( anObjZLevel ) )
658 aResList << QString( "%1.SetZLevel( %2 )" )
659 .arg( aName ).arg( anObjZLevel );
660 aResList << QString( "" );
667 QString HYDROData_Entity::getPyTypeID() const
669 //DEBTRACE("HYDROData_Entity::getPyTypeID " << GetKind());
672 case KIND_IMAGE: return "KIND_IMAGE";
673 case KIND_POLYLINE: return "KIND_POLYLINE";
674 case KIND_BATHYMETRY: return "KIND_BATHYMETRY";
675 case KIND_ALTITUDE: return "KIND_ALTITUDE";
676 case KIND_IMMERSIBLE_ZONE: return "KIND_IMMERSIBLE_ZONE";
677 case KIND_RIVER: return "KIND_RIVER";
678 case KIND_STREAM: return "KIND_STREAM";
679 case KIND_CONFLUENCE: return "KIND_CONFLUENCE";
680 case KIND_CHANNEL: return "KIND_CHANNEL";
681 case KIND_OBSTACLE: return "KIND_OBSTACLE";
682 case KIND_DIGUE: return "KIND_DIGUE";
683 case KIND_PROFILE: return "KIND_PROFILE";
684 case KIND_PROFILEUZ: return "KIND_PROFILEUZ";
685 case KIND_POLYLINEXY: return "KIND_POLYLINEXY";
686 case KIND_CALCULATION: return "KIND_CALCULATION";
687 case KIND_ZONE: return "KIND_ZONE";
688 case KIND_REGION: return "KIND_REGION";
689 case KIND_VISUAL_STATE: return "KIND_VISUAL_STATE";
690 case KIND_ARTIFICIAL_OBJECT: return "KIND_ARTIFICIAL_OBJECT";
691 case KIND_NATURAL_OBJECT: return "KIND_NATURAL_OBJECT";
692 case KIND_DUMMY_3D: return "KIND_DUMMY_3D";
693 case KIND_SHAPES_GROUP: return "KIND_SHAPES_GROUP";
694 case KIND_SPLIT_GROUP: return "KIND_SPLIT_GROUP";
695 case KIND_STREAM_ALTITUDE: return "KIND_STREAM_ALTITUDE";
696 case KIND_OBSTACLE_ALTITUDE: return "KIND_OBSTACLE_ALTITUDE";
697 case KIND_STRICKLER_TABLE: return "KIND_STRICKLER_TABLE";
698 case KIND_LAND_COVER_OBSOLETE: return "";
699 case KIND_CHANNEL_ALTITUDE: return "KIND_CHANNEL_ALTITUDE";
700 case KIND_LAND_COVER_MAP: return "KIND_LAND_COVER_MAP";
701 default: return "KIND_UNKNOWN"; ///! Unrecognized object
705 void HYDROData_Entity::setPythonReferenceObject( const QString& thePyScriptPath,
706 MapOfTreatedObjects& theTreatedObjects,
707 QStringList& theScript,
708 const Handle(HYDROData_Entity)& theRefObject,
709 const QString& theMethod ) const
711 if ( !checkObjectPythonDefinition( thePyScriptPath, theTreatedObjects, theScript, theRefObject ) )
714 QString aRefObjName = theRefObject->GetObjPyName();
716 QString anObjName = GetObjPyName();
717 theScript << QString( "%1.%2( %3 )" )
718 .arg( anObjName ).arg( theMethod ).arg( aRefObjName );
721 bool HYDROData_Entity::checkObjectPythonDefinition( const QString& thePyScriptPath,
722 MapOfTreatedObjects& theTreatedObjects,
723 QStringList& theScript,
724 const Handle(HYDROData_Entity)& theRefObject ) const
726 if ( theRefObject.IsNull() )
729 QString aRefObjName = theRefObject->GetName();
730 if ( aRefObjName.isEmpty() )
733 if ( theTreatedObjects.contains( aRefObjName ) )
736 // The definition of reference object must be dumped before this
737 QStringList aRefObjDump = theRefObject->DumpToPython( thePyScriptPath, theTreatedObjects );
738 if ( aRefObjDump.isEmpty() )
741 QStringList aTmpList = theScript;
742 theScript = aRefObjDump;
744 theScript << QString( "" );
745 theScript << aTmpList;
747 theTreatedObjects.insert( aRefObjName, theRefObject );
752 void HYDROData_Entity::setPythonObjectColor( QStringList& theScript,
753 const QColor& theColor,
754 const QColor& theDefaultColor,
755 const QString& theMethod ) const
757 if ( theColor == theDefaultColor )
758 return; //Do not set the color for object if it like default
760 QString anObjName = GetObjPyName();
761 theScript << QString( "%1.%2( QColor( %3, %4, %5, %6 ) )" )
762 .arg( anObjName ).arg( theMethod )
763 .arg( theColor.red() ).arg( theColor.green() )
764 .arg( theColor.blue() ).arg( theColor.alpha() );
767 void HYDROData_Entity::findPythonReferenceObject( QStringList& theScript,
768 QString defName) const
770 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
771 if ( aDocument.IsNull() )
774 if (defName.isEmpty())
775 theScript << QString( "%1 = %2.FindObjectByName( \"%3\" )" ).arg( GetObjPyName() )
776 .arg( aDocument->GetDocPyName() )
777 .arg( GetDefaultName() );
779 theScript << QString( "%1 = %2.FindObjectByName( \"%3\" )" ).arg( GetObjPyName() )
780 .arg( aDocument->GetDocPyName() )
784 void HYDROData_Entity::SetNameInDumpPython(QStringList& theScript,
785 QString theName) const
787 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
788 if ( aDocument.IsNull() )
791 if (theName.isEmpty())
792 theScript << QString( "%1.SetName( \"%2\" )" ).arg( GetObjPyName() )
795 theScript << QString( "%1.SetName( \"%2\" )" ).arg( GetObjPyName() )
799 void HYDROData_Entity::SetShape( int theTag, const TopoDS_Shape& theShape )
801 TNaming_Builder aBuilder( myLab.FindChild( theTag ) );
802 aBuilder.Generated( theShape );
805 TopoDS_Shape HYDROData_Entity::GetShape( int theTag ) const
807 TDF_Label aShapeLabel = myLab.FindChild( theTag, false );
808 if ( !aShapeLabel.IsNull() )
810 Handle(TNaming_NamedShape) aNamedShape;
811 if ( aShapeLabel.FindAttribute( TNaming_NamedShape::GetID(), aNamedShape ) )
812 return aNamedShape->Get();
814 return TopoDS_Shape();
817 void HYDROData_Entity::SetDouble( int theTag, double theValue )
819 Handle(TDataStd_Real) anAttr;
820 TDF_Label aLabel = myLab.FindChild( theTag );
821 if( !aLabel.FindAttribute( TDataStd_Real::GetID(), anAttr ) )
823 anAttr = new TDataStd_Real();
824 anAttr->SetID(TDataStd_Real::GetID());
825 aLabel.AddAttribute( anAttr );
827 anAttr->Set( theValue );
830 double HYDROData_Entity::GetDouble( int theTag, double theDefValue ) const
832 Handle(TDataStd_Real) anAttr;
833 TDF_Label aLabel = myLab.FindChild( theTag );
834 if( !aLabel.FindAttribute( TDataStd_Real::GetID(), anAttr ) )
837 return anAttr->Get();
840 void HYDROData_Entity::SetInteger( int theTag, int theValue )
842 Handle(TDataStd_Integer) anAttr;
843 TDF_Label aLabel = myLab.FindChild( theTag );
844 if( !aLabel.FindAttribute( TDataStd_Integer::GetID(), anAttr ) )
846 anAttr = new TDataStd_Integer();
847 anAttr->SetID(TDataStd_Integer::GetID());
848 aLabel.AddAttribute(anAttr);
850 anAttr->Set( theValue );
853 int HYDROData_Entity::GetInteger( int theTag, int theDefValue ) const
855 Handle(TDataStd_Integer) anAttr;
856 TDF_Label aLabel = myLab.FindChild( theTag );
857 if( !aLabel.FindAttribute( TDataStd_Integer::GetID(), anAttr ) )
860 return anAttr->Get();
863 bool HYDROData_Entity::CompareLabels(const Handle(HYDROData_Entity)& theOtherObj)
865 if ( !theOtherObj.IsNull() )
866 return this->Label() == theOtherObj->Label();