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::GetType() const
82 return Type( GetKind() );
85 QString HYDROData_Entity::Type( ObjectKind theKind )
99 case KIND_IMMERSIBLE_ZONE:
100 return "Immersible_zone";
105 case KIND_CONFLUENCE:
117 case KIND_POLYLINEXY:
118 return "Polyline_XY";
119 case KIND_CALCULATION:
120 return "Calculation_case";
125 case KIND_VISUAL_STATE:
126 return "Visual_state";
127 case KIND_ARTIFICIAL_OBJECT:
128 return "Artificial_object";
129 case KIND_NATURAL_OBJECT:
130 return "Natural_object";
133 case KIND_SHAPES_GROUP:
134 return "Shapes_group";
135 case KIND_SPLIT_GROUP:
136 return "Split_group";
137 case KIND_STREAM_ALTITUDE:
138 return "Stream_altitude";
139 case KIND_OBSTACLE_ALTITUDE:
140 return "Obstacle_altitude";
141 case KIND_STRICKLER_TABLE:
142 return "Strickler_table";
143 case KIND_LAND_COVER_OBSOLETE:
145 case KIND_CHANNEL_ALTITUDE:
146 return "Channel_altitude";
147 case KIND_LAND_COVER_MAP:
148 return "Land_cover_map";
155 QString HYDROData_Entity::GetObjPyName() const
157 QString aName = GetName();
158 aName.replace(QRegExp("[\\W]"), "_");
160 if( aName[0].isDigit() )
161 aName = GetType() + "_" + aName;
166 QString HYDROData_Entity::GetDefaultName() const
170 TDF_Label aLabel = myLab.FindChild(DataTag_DefaultName, false);
171 if (!aLabel.IsNull())
173 Handle(TDataStd_AsciiString) anAsciiStr;
174 if (aLabel.FindAttribute(TDataStd_AsciiString::GetID(), anAsciiStr))
175 aName = QString(anAsciiStr->Get().ToCString());
184 void HYDROData_Entity::SetName(const QString& theName, bool isDefault)
186 Handle(TDataStd_Name) A = TDataStd_Name::Set(myLab, TCollection_ExtendedString(theName.toLatin1().constData()));
187 A->SetID(TDataStd_Name::GetID());
190 TDF_Label aDefaultNameLabel = myLab.FindChild( DataTag_DefaultName, true );
191 if ( aDefaultNameLabel.IsNull() )
193 Handle(TDataStd_AsciiString) theDefaultName;
195 if ( !aDefaultNameLabel.FindAttribute( TDataStd_AsciiString::GetID(), theDefaultName ))
197 TCollection_AsciiString aName = theName.toStdString().c_str();
198 theDefaultName = TDataStd_AsciiString::Set(myLab.FindChild( DataTag_DefaultName), aName );
199 theDefaultName->SetID( TDataStd_AsciiString::GetID() );
204 QStringList HYDROData_Entity::DumpToPython( const QString& thePyScriptPath,
205 MapOfTreatedObjects& theTreatedObjects ) const
207 QStringList anEmptyList;
211 void HYDROData_Entity::Update()
216 void HYDROData_Entity::UpdateLocalCS( double theDx, double theDy )
218 //On the base level no actions are necessary
221 bool HYDROData_Entity::IsHas2dPrs() const
226 void HYDROData_Entity::Show()
231 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
232 if ( aDocument.IsNull() )
235 aDocument->Show( this );
238 QVariant HYDROData_Entity::GetDataVariant()
243 void HYDROData_Entity::ClearChanged()
245 Handle(TDataStd_Integer) A = TDataStd_Integer::Set( myLab.FindChild( DataTag_GeomChange ), 0 );
246 A->SetID(TDataStd_Integer::GetID());
249 int HYDROData_Entity::GetGeomChangeFlag() const
251 int aGeomChangeFlag = 0;
252 Handle(TDataStd_Integer) aGeomChangeAttr;
253 TDF_Label aGeomChangeLab = myLab.FindChild( DataTag_GeomChange );
254 aGeomChangeLab.FindAttribute( TDataStd_Integer::GetID(), aGeomChangeAttr );
255 if ( !aGeomChangeAttr.IsNull() )
256 aGeomChangeFlag = aGeomChangeAttr->Get();
257 return aGeomChangeFlag;
260 void HYDROData_Entity::Changed( Geometry theChangedGeometry )
262 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
263 if( aDocument.IsNull() )
266 int aGeomChangeFlag = 0;
267 Handle(TDataStd_Integer) aGeomChangeAttr;
268 TDF_Label aGeomChangeLab = myLab.FindChild( DataTag_GeomChange );
269 aGeomChangeLab.FindAttribute( TDataStd_Integer::GetID(), aGeomChangeAttr );
270 if ( !aGeomChangeAttr.IsNull() )
271 aGeomChangeFlag = aGeomChangeAttr->Get();
273 int aBitsToChange = ( myGeom & theChangedGeometry );
274 if( aBitsToChange == 0 )
277 aGeomChangeFlag = ( aGeomChangeFlag | aBitsToChange );
278 Handle(TDataStd_Integer) anAttr = TDataStd_Integer::Set( aGeomChangeLab, aGeomChangeFlag );
279 anAttr->SetID( TDataStd_Integer::GetID() );
281 HYDROData_Iterator anIter( aDocument );
282 for ( ; anIter.More(); anIter.Next() )
284 Handle(HYDROData_Entity) anObject = anIter.Current();
285 if( anObject.IsNull() )
287 HYDROData_SequenceOfObjects aRefSeq = anObject->GetAllReferenceObjects();
288 for ( int i = 1, n = aRefSeq.Length(); i <= n; ++i )
290 Handle(HYDROData_Entity) aRefObject = aRefSeq.Value( i );
291 if( aRefObject->Label()==myLab )
292 anObject->Changed( theChangedGeometry );
297 bool HYDROData_Entity::IsMustBeUpdated( Geometry theGeom ) const
299 return ( ( GetGeomChangeFlag() & theGeom ) != 0 );
302 bool HYDROData_Entity::CanBeUpdated() const
307 bool HYDROData_Entity::IsRemoved() const
309 return !myLab.HasAttribute();
312 void HYDROData_Entity::Remove()
314 return myLab.ForgetAllAttributes( true );
317 bool HYDROData_Entity::CanRemove()
322 HYDROData_Entity::HYDROData_Entity( Geometry theGeom )
327 HYDROData_Entity::~HYDROData_Entity()
331 void HYDROData_Entity::CopyTo( const Handle(HYDROData_Entity)& theDestination,
332 bool isGenerateNewName ) const
334 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
335 if ( aDocument.IsNull() ) {
339 TDF_CopyLabel aCopy(myLab, theDestination->Label());
342 if( isGenerateNewName )
344 // generate a new unique name for the clone object:
345 // case 1: Image_1 -> Image_2
346 // case 2: ImageObj -> ImageObj_1
347 QString aName = theDestination->GetName();
348 QString aPrefix = aName;
349 if( aName.contains( '_' ) ) { // case 1
350 QString aSuffix = aName.section( '_', -1 );
351 bool anIsInteger = false;
352 aSuffix.toInt( &anIsInteger );
354 aPrefix = aName.section( '_', 0, -2 );
359 aName = HYDROData_Tool::GenerateObjectName( aDocument, aPrefix );
360 theDestination->SetName( aName );
364 Handle(HYDROData_Entity) HYDROData_Entity::GetFatherObject() const
366 Handle(HYDROData_Entity) aFather;
368 if ( !myLab.IsNull() )
370 TDF_Label aFatherLabel = myLab.Father();
372 while ( aFather.IsNull() && !aFatherLabel.IsNull() && !aFatherLabel.IsRoot() )
374 aFather = HYDROData_Iterator::Object( aFatherLabel );
375 aFatherLabel = aFatherLabel.Father();
382 HYDROData_SequenceOfObjects HYDROData_Entity::GetAllReferenceObjects() const
384 return HYDROData_SequenceOfObjects();
387 bool HYDROData_Entity::GetZLevel( Standard_Integer& theLevel ) const
391 TDF_Label aLabel = myLab.FindChild( DataTag_ZLevel, false );
392 if ( !aLabel.IsNull() )
394 Handle(TDataStd_Integer) anIntVal;
395 if ( aLabel.FindAttribute( TDataStd_Integer::GetID(), anIntVal ) )
397 theLevel = anIntVal->Get();
405 void HYDROData_Entity::SetZLevel( const Standard_Integer& theLevel )
407 Handle(TDataStd_Integer) A = TDataStd_Integer::Set( myLab.FindChild( DataTag_ZLevel ), theLevel );
408 A->SetID(TDataStd_Integer::GetID());
411 void HYDROData_Entity::RemoveZLevel()
413 TDF_Label aLabel = myLab.FindChild( DataTag_ZLevel, false );
414 if ( !aLabel.IsNull() )
415 aLabel.ForgetAllAttributes();
418 void HYDROData_Entity::SetLabel( const TDF_Label& theLabel )
423 void HYDROData_Entity::SaveByteArray( const int theTag,
427 TDF_Label aLab = theTag == 0 ? myLab : myLab.FindChild(theTag);
428 // array is empty, remove the attribute
430 aLab.ForgetAttribute(TDataStd_ByteArray::GetID());
433 // store data of image in byte array
434 Handle(TDataStd_ByteArray) aData;
435 if (!aLab.FindAttribute(TDataStd_ByteArray::GetID(), aData)) {
436 aData = TDataStd_ByteArray::Set(aLab, 1, theLen);
437 aData->SetID( TDataStd_ByteArray::GetID() );
439 Standard_Byte* Byte0 = &(aData->InternalArray()->ChangeArray1().ChangeFirst());
440 memcpy(Byte0, theData, theLen * sizeof (char));
441 // copy bytes one by one
442 if (aData->Length() != theLen) {
443 Handle(TColStd_HArray1OfByte) aNewData = new TColStd_HArray1OfByte(1, theLen);
444 for(int a = 0; a < theLen; a++)
445 aNewData->SetValue(a + 1, theData[a]);
446 aData->ChangeArray(aNewData);
450 // for(int a = 0; a < theLen; a++)
451 // aData->SetValue(a + 1, theData[a]);
455 const char* HYDROData_Entity::ByteArray(const int theTag, int& theLen) const
457 TDF_Label aLab = theTag == 0 ? myLab : myLab.FindChild(theTag);
458 Handle(TDataStd_ByteArray) aData;
459 if (!aLab.FindAttribute(TDataStd_ByteArray::GetID(), aData))
460 return NULL; // return empty image if there is no array
461 theLen = aData->Length();
463 return (const char*)(&(aData->InternalArray()->ChangeArray1().ChangeValue(1)));
467 int HYDROData_Entity::NbReferenceObjects( const int theTag ) const
469 Handle(TDataStd_ReferenceList) aRefs = getReferenceList( theTag, false );
470 return aRefs.IsNull() ? 0 : aRefs->Extent();
473 bool HYDROData_Entity::HasReference( const Handle(HYDROData_Entity)& theObj,
474 const int theTag ) const
476 if ( theObj.IsNull() )
479 Handle(TDataStd_ReferenceList) aRefs = getReferenceList( theTag, false );
480 if ( aRefs.IsNull() || aRefs->IsEmpty() )
483 TDF_ListIteratorOfLabelList aListIt( aRefs->List() );
484 for ( ; aListIt.More(); aListIt.Next() )
486 const TDF_Label& aRefLabel = aListIt.Value();
487 if ( theObj->Label() == aRefLabel )
494 void HYDROData_Entity::AddReferenceObject( const Handle(HYDROData_Entity)& theObj,
497 if ( theObj.IsNull() )
500 Handle(TDataStd_ReferenceList) aRefs = getReferenceList( theTag, true );
501 aRefs->Append( theObj->Label() );
502 aRefs->SetID(TDataStd_ReferenceList::GetID());
505 void HYDROData_Entity::SetReferenceObject( const Handle(HYDROData_Entity)& theObj,
509 if ( theObj.IsNull() )
511 RemoveReferenceObject( theTag, theIndex );
515 Handle(TDataStd_ReferenceList) aRefs = getReferenceList( theTag, true );
517 if ( theIndex >= aRefs->Extent() )
519 aRefs->Append( theObj->Label() );
521 else if ( theIndex < 0 )
523 aRefs->Prepend( theObj->Label() );
527 RemoveReferenceObject( theTag, theIndex );
529 Handle(HYDROData_Entity) aBeforeObj = GetReferenceObject( theTag, theIndex );
531 aRefs = getReferenceList( theTag, true ); // because reference list can be removed
532 if ( !aBeforeObj.IsNull() )
533 aRefs->InsertBefore( theObj->Label(), aBeforeObj->Label() );
535 aRefs->Append( theObj->Label() );
539 void HYDROData_Entity::InsertReferenceObject( const Handle(HYDROData_Entity)& theObj,
541 const int theBeforeIndex )
543 if ( theObj.IsNull() )
546 Handle(TDataStd_ReferenceList) aRefs = getReferenceList( theTag, true );
548 if ( theBeforeIndex >= aRefs->Extent() )
550 aRefs->Append( theObj->Label() );
552 else if ( theBeforeIndex < 0 )
554 aRefs->Prepend( theObj->Label() );
558 Handle(HYDROData_Entity) aBeforeObj = GetReferenceObject( theTag, theBeforeIndex );
559 if ( !aBeforeObj.IsNull() )
560 aRefs->InsertBefore( theObj->Label(), aBeforeObj->Label() );
562 aRefs->Append( theObj->Label() );
566 void HYDROData_Entity::SetReferenceObjects( const HYDROData_SequenceOfObjects& theObjects,
569 ClearReferenceObjects( theTag );
570 if ( theObjects.IsEmpty() )
573 HYDROData_SequenceOfObjects::Iterator anIter( theObjects );
574 for ( ; anIter.More(); anIter.Next() )
575 AddReferenceObject( anIter.Value(), theTag );
578 Handle(HYDROData_Entity) HYDROData_Entity::GetReferenceObject( const int theTag,
579 const int theIndex ) const
581 //DEBTRACE("GetReferenceObject " << theTag << " " << theIndex);
582 Handle(HYDROData_Entity) aRes;
584 Handle(TDataStd_ReferenceList) aRefs = getReferenceList( theTag, false );
585 if ( aRefs.IsNull() || theIndex < 0 || theIndex >= aRefs->Extent() )
588 TDF_ListIteratorOfLabelList anIter( aRefs->List() );
589 for ( int anIndex = 0; anIndex != theIndex && anIter.More(); anIter.Next(), ++anIndex );
591 const TDF_Label& aRefLabel = anIter.Value();
592 aRes = HYDROData_Iterator::Object( aRefLabel );
597 HYDROData_SequenceOfObjects HYDROData_Entity::GetReferenceObjects( const int theTag ) const
599 HYDROData_SequenceOfObjects aRes;
601 Handle(TDataStd_ReferenceList) aRefs = getReferenceList( theTag, false );
602 if ( aRefs.IsNull() )
605 TDF_ListIteratorOfLabelList anIter( aRefs->List() );
606 for ( ; anIter.More(); anIter.Next() )
608 const TDF_Label& aRefLabel = anIter.Value();
610 Handle(HYDROData_Entity) aRefObject = HYDROData_Iterator::Object( aRefLabel );
611 if ( aRefObject.IsNull() )
614 aRes.Append( aRefObject );
620 void HYDROData_Entity::RemoveReferenceObject( const TDF_Label& theRefLabel,
623 Handle(TDataStd_ReferenceList) aRefs = getReferenceList( theTag, false );
624 if ( aRefs.IsNull() )
627 if ( aRefs->Extent() == 1 )
629 // remove all if only one
630 ClearReferenceObjects( theTag );
634 aRefs->Remove( theRefLabel );
637 void HYDROData_Entity::RemoveReferenceObject( const int theTag,
640 Handle(TDataStd_ReferenceList) aRefs = getReferenceList( theTag, false );
641 if ( aRefs.IsNull() )
644 if ( aRefs->Extent() == 1 && theIndex == 0 )
646 // remove all if only one
647 ClearReferenceObjects( theTag );
652 TDF_ListIteratorOfLabelList anIter( aRefs->List() );
653 for ( ; anIndex != theIndex && anIter.More(); anIter.Next(), ++anIndex );
655 if ( anIndex != theIndex || !anIter.More() )
658 const TDF_Label& aRefLabel = anIter.Value();
659 aRefs->Remove( aRefLabel );
662 void HYDROData_Entity::ClearReferenceObjects( const int theTag )
664 TDF_Label aSetLabel = theTag == 0 ? myLab : myLab.FindChild( theTag );
665 aSetLabel.ForgetAttribute( TDataStd_ReferenceList::GetID() );
668 Handle(TDataStd_ReferenceList) HYDROData_Entity::getReferenceList( const int theTag,
669 const bool theIsCreate ) const
671 //DEBTRACE("getReferenceList " << theTag << " " << theIsCreate);
672 TDF_Label aLabel = theTag == 0 ? myLab : myLab.FindChild( theTag );
674 Handle(TDataStd_ReferenceList) aRefs;
675 if ( !aLabel.FindAttribute( TDataStd_ReferenceList::GetID(), aRefs ) && theIsCreate )
677 aRefs = TDataStd_ReferenceList::Set( aLabel );
678 aRefs->SetID(TDataStd_ReferenceList::GetID());
683 void HYDROData_Entity::SetColor( const QColor& theColor,
686 TDF_Label aLabel = theTag == 0 ? myLab : myLab.FindChild( theTag );
688 Handle(TDataStd_IntegerArray) aColorArray;
689 if ( !aLabel.FindAttribute( TDataStd_IntegerArray::GetID(), aColorArray ) )
691 aColorArray = TDataStd_IntegerArray::Set( aLabel, 1, 4 );
692 aColorArray->SetID(TDataStd_IntegerArray::GetID());
695 aColorArray->SetValue( 1, theColor.red() );
696 aColorArray->SetValue( 2, theColor.green() );
697 aColorArray->SetValue( 3, theColor.blue() );
698 aColorArray->SetValue( 4, theColor.alpha() );
701 QColor HYDROData_Entity::GetColor( const QColor& theDefColor,
702 const int theTag ) const
704 QColor aResColor = theDefColor;
706 TDF_Label aLabel = theTag == 0 ? myLab : myLab.FindChild( theTag );
708 Handle(TDataStd_IntegerArray) aColorArray;
709 if ( aLabel.FindAttribute( TDataStd_IntegerArray::GetID(), aColorArray ) )
711 aResColor.setRed( aColorArray->Value( 1 ) );
712 aResColor.setGreen( aColorArray->Value( 2 ) );
713 aResColor.setBlue( aColorArray->Value( 3 ) );
714 aResColor.setAlpha( aColorArray->Value( 4 ) );
720 QStringList HYDROData_Entity::dumpObjectCreation( MapOfTreatedObjects& theTreatedObjects ) const
722 QStringList aResList;
724 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
725 if ( aDocument.IsNull() )
728 QString aDocName = aDocument->GetDocPyName();
729 QString aName = GetObjPyName();
731 aResList << QString( "%1 = %2.CreateObject( %3 )" )
732 .arg( aName ).arg( aDocName ).arg( getPyTypeID() );
733 aResList << QString( "%1.SetName( \"%2\" )" )
734 .arg( aName ).arg( GetName() );
735 aResList << QString( "" );
739 // Dump object z-level in viewer
740 Standard_Integer anObjZLevel = -1;
741 if ( GetZLevel( anObjZLevel ) )
743 aResList << QString( "%1.SetZLevel( %2 )" )
744 .arg( aName ).arg( anObjZLevel );
745 aResList << QString( "" );
752 QString HYDROData_Entity::getPyTypeID() const
754 //DEBTRACE("HYDROData_Entity::getPyTypeID " << GetKind());
757 case KIND_IMAGE: return "KIND_IMAGE";
758 case KIND_POLYLINE: return "KIND_POLYLINE";
759 case KIND_BATHYMETRY: return "KIND_BATHYMETRY";
760 case KIND_ALTITUDE: return "KIND_ALTITUDE";
761 case KIND_IMMERSIBLE_ZONE: return "KIND_IMMERSIBLE_ZONE";
762 case KIND_RIVER: return "KIND_RIVER";
763 case KIND_STREAM: return "KIND_STREAM";
764 case KIND_CONFLUENCE: return "KIND_CONFLUENCE";
765 case KIND_CHANNEL: return "KIND_CHANNEL";
766 case KIND_OBSTACLE: return "KIND_OBSTACLE";
767 case KIND_DIGUE: return "KIND_DIGUE";
768 case KIND_PROFILE: return "KIND_PROFILE";
769 case KIND_PROFILEUZ: return "KIND_PROFILEUZ";
770 case KIND_POLYLINEXY: return "KIND_POLYLINEXY";
771 case KIND_CALCULATION: return "KIND_CALCULATION";
772 case KIND_ZONE: return "KIND_ZONE";
773 case KIND_REGION: return "KIND_REGION";
774 case KIND_VISUAL_STATE: return "KIND_VISUAL_STATE";
775 case KIND_ARTIFICIAL_OBJECT: return "KIND_ARTIFICIAL_OBJECT";
776 case KIND_NATURAL_OBJECT: return "KIND_NATURAL_OBJECT";
777 case KIND_DUMMY_3D: return "KIND_DUMMY_3D";
778 case KIND_SHAPES_GROUP: return "KIND_SHAPES_GROUP";
779 case KIND_SPLIT_GROUP: return "KIND_SPLIT_GROUP";
780 case KIND_STREAM_ALTITUDE: return "KIND_STREAM_ALTITUDE";
781 case KIND_OBSTACLE_ALTITUDE: return "KIND_OBSTACLE_ALTITUDE";
782 case KIND_STRICKLER_TABLE: return "KIND_STRICKLER_TABLE";
783 case KIND_LAND_COVER_OBSOLETE: return "";
784 case KIND_CHANNEL_ALTITUDE: return "KIND_CHANNEL_ALTITUDE";
785 case KIND_LAND_COVER_MAP: return "KIND_LAND_COVER_MAP";
786 default: return "KIND_UNKNOWN"; ///! Unrecognized object
790 void HYDROData_Entity::setPythonReferenceObject( const QString& thePyScriptPath,
791 MapOfTreatedObjects& theTreatedObjects,
792 QStringList& theScript,
793 const Handle(HYDROData_Entity)& theRefObject,
794 const QString& theMethod ) const
796 if ( !checkObjectPythonDefinition( thePyScriptPath, theTreatedObjects, theScript, theRefObject ) )
799 QString aRefObjName = theRefObject->GetObjPyName();
801 QString anObjName = GetObjPyName();
802 theScript << QString( "%1.%2( %3 )" )
803 .arg( anObjName ).arg( theMethod ).arg( aRefObjName );
806 bool HYDROData_Entity::checkObjectPythonDefinition( const QString& thePyScriptPath,
807 MapOfTreatedObjects& theTreatedObjects,
808 QStringList& theScript,
809 const Handle(HYDROData_Entity)& theRefObject ) const
811 if ( theRefObject.IsNull() )
814 QString aRefObjName = theRefObject->GetName();
815 if ( aRefObjName.isEmpty() )
818 if ( theTreatedObjects.contains( aRefObjName ) )
821 // The definition of reference object must be dumped before this
822 QStringList aRefObjDump = theRefObject->DumpToPython( thePyScriptPath, theTreatedObjects );
823 if ( aRefObjDump.isEmpty() )
826 QStringList aTmpList = theScript;
827 theScript = aRefObjDump;
829 theScript << QString( "" );
830 theScript << aTmpList;
832 theTreatedObjects.insert( aRefObjName, theRefObject );
837 void HYDROData_Entity::setPythonObjectColor( QStringList& theScript,
838 const QColor& theColor,
839 const QColor& theDefaultColor,
840 const QString& theMethod ) const
842 if ( theColor == theDefaultColor )
843 return; //Do not set the color for object if it like default
845 QString anObjName = GetObjPyName();
846 theScript << QString( "%1.%2( QColor( %3, %4, %5, %6 ) )" )
847 .arg( anObjName ).arg( theMethod )
848 .arg( theColor.red() ).arg( theColor.green() )
849 .arg( theColor.blue() ).arg( theColor.alpha() );
852 void HYDROData_Entity::findPythonReferenceObject( QStringList& theScript,
853 QString defName) const
855 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
856 if ( aDocument.IsNull() )
859 if (defName.isEmpty())
860 theScript << QString( "%1 = %2.FindObjectByName( \"%3\" )" ).arg( GetObjPyName() )
861 .arg( aDocument->GetDocPyName() )
862 .arg( GetDefaultName() );
864 theScript << QString( "%1 = %2.FindObjectByName( \"%3\" )" ).arg( GetObjPyName() )
865 .arg( aDocument->GetDocPyName() )
869 void HYDROData_Entity::SetNameInDumpPython(QStringList& theScript,
870 QString theName) const
872 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
873 if ( aDocument.IsNull() )
876 if (theName.isEmpty())
877 theScript << QString( "%1.SetName( \"%2\" )" ).arg( GetObjPyName() )
880 theScript << QString( "%1.SetName( \"%2\" )" ).arg( GetObjPyName() )
884 void HYDROData_Entity::SetShape( int theTag, const TopoDS_Shape& theShape )
886 TNaming_Builder aBuilder( myLab.FindChild( theTag ) );
887 aBuilder.Generated( theShape );
888 aBuilder.NamedShape()->SetID(TNaming_NamedShape::GetID());
891 TopoDS_Shape HYDROData_Entity::GetShape( int theTag ) const
893 TDF_Label aShapeLabel = myLab.FindChild( theTag, false );
894 if ( !aShapeLabel.IsNull() )
896 Handle(TNaming_NamedShape) aNamedShape;
897 if ( aShapeLabel.FindAttribute( TNaming_NamedShape::GetID(), aNamedShape ) )
898 return aNamedShape->Get();
900 return TopoDS_Shape();
903 void HYDROData_Entity::SetDouble( int theTag, double theValue )
905 Handle(TDataStd_Real) anAttr;
906 TDF_Label aLabel = myLab.FindChild( theTag );
907 if( !aLabel.FindAttribute( TDataStd_Real::GetID(), anAttr ) )
909 anAttr = new TDataStd_Real();
910 anAttr->SetID(TDataStd_Real::GetID());
911 aLabel.AddAttribute( anAttr );
913 anAttr->Set( theValue );
916 double HYDROData_Entity::GetDouble( int theTag, double theDefValue ) const
918 Handle(TDataStd_Real) anAttr;
919 TDF_Label aLabel = myLab.FindChild( theTag );
920 if( !aLabel.FindAttribute( TDataStd_Real::GetID(), anAttr ) )
923 return anAttr->Get();
926 void HYDROData_Entity::SetInteger( int theTag, int theValue )
928 Handle(TDataStd_Integer) anAttr;
929 TDF_Label aLabel = myLab.FindChild( theTag );
930 if( !aLabel.FindAttribute( TDataStd_Integer::GetID(), anAttr ) )
932 anAttr = new TDataStd_Integer();
933 anAttr->SetID(TDataStd_Integer::GetID());
934 aLabel.AddAttribute(anAttr);
936 anAttr->Set( theValue );
939 int HYDROData_Entity::GetInteger( int theTag, int theDefValue ) const
941 Handle(TDataStd_Integer) anAttr;
942 TDF_Label aLabel = myLab.FindChild( theTag );
943 if( !aLabel.FindAttribute( TDataStd_Integer::GetID(), anAttr ) )
946 return anAttr->Get();
949 bool HYDROData_Entity::CompareLabels(const Handle(HYDROData_Entity)& theOtherObj)
951 if ( !theOtherObj.IsNull() )
952 return this->Label() == theOtherObj->Label();