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";
153 case KIND_BC_POLYGON:
154 return "Boundary_Polygon";
159 QString HYDROData_Entity::GetObjPyName() const
161 QString aName = GetName();
162 aName.replace(QRegExp("[\\W]"), "_");
164 if( aName[0].isDigit() )
165 aName = GetType() + "_" + aName;
170 QString HYDROData_Entity::GetDefaultName() const
174 TDF_Label aLabel = myLab.FindChild(DataTag_DefaultName, false);
175 if (!aLabel.IsNull())
177 Handle(TDataStd_AsciiString) anAsciiStr;
178 if (aLabel.FindAttribute(TDataStd_AsciiString::GetID(), anAsciiStr))
179 aName = QString(anAsciiStr->Get().ToCString());
188 void HYDROData_Entity::SetName(const QString& theName, bool isDefault)
190 Handle(TDataStd_Name) A = TDataStd_Name::Set(myLab, TCollection_ExtendedString(theName.toLatin1().constData()));
191 A->SetID(TDataStd_Name::GetID());
194 TDF_Label aDefaultNameLabel = myLab.FindChild( DataTag_DefaultName, true );
195 if ( aDefaultNameLabel.IsNull() )
197 Handle(TDataStd_AsciiString) theDefaultName;
199 if ( !aDefaultNameLabel.FindAttribute( TDataStd_AsciiString::GetID(), theDefaultName ))
201 TCollection_AsciiString aName = theName.toStdString().c_str();
202 theDefaultName = TDataStd_AsciiString::Set(myLab.FindChild( DataTag_DefaultName), aName );
203 theDefaultName->SetID( TDataStd_AsciiString::GetID() );
208 QStringList HYDROData_Entity::DumpToPython( const QString& thePyScriptPath,
209 MapOfTreatedObjects& theTreatedObjects ) const
211 QStringList anEmptyList;
215 void HYDROData_Entity::Update()
220 void HYDROData_Entity::UpdateLocalCS( double theDx, double theDy )
222 //On the base level no actions are necessary
225 bool HYDROData_Entity::IsHas2dPrs() const
230 void HYDROData_Entity::Show()
235 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
236 if ( aDocument.IsNull() )
239 aDocument->Show( this );
242 QVariant HYDROData_Entity::GetDataVariant()
247 void HYDROData_Entity::ClearChanged()
249 Handle(TDataStd_Integer) A = TDataStd_Integer::Set( myLab.FindChild( DataTag_GeomChange ), 0 );
250 A->SetID(TDataStd_Integer::GetID());
253 int HYDROData_Entity::GetGeomChangeFlag() const
255 int aGeomChangeFlag = 0;
256 Handle(TDataStd_Integer) aGeomChangeAttr;
257 TDF_Label aGeomChangeLab = myLab.FindChild( DataTag_GeomChange );
258 aGeomChangeLab.FindAttribute( TDataStd_Integer::GetID(), aGeomChangeAttr );
259 if ( !aGeomChangeAttr.IsNull() )
260 aGeomChangeFlag = aGeomChangeAttr->Get();
261 return aGeomChangeFlag;
264 void HYDROData_Entity::Changed( Geometry theChangedGeometry )
266 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
267 if( aDocument.IsNull() )
270 int aGeomChangeFlag = 0;
271 Handle(TDataStd_Integer) aGeomChangeAttr;
272 TDF_Label aGeomChangeLab = myLab.FindChild( DataTag_GeomChange );
273 aGeomChangeLab.FindAttribute( TDataStd_Integer::GetID(), aGeomChangeAttr );
274 if ( !aGeomChangeAttr.IsNull() )
275 aGeomChangeFlag = aGeomChangeAttr->Get();
277 int aBitsToChange = ( myGeom & theChangedGeometry );
278 if( aBitsToChange == 0 )
281 aGeomChangeFlag = ( aGeomChangeFlag | aBitsToChange );
282 Handle(TDataStd_Integer) anAttr = TDataStd_Integer::Set( aGeomChangeLab, aGeomChangeFlag );
283 anAttr->SetID( TDataStd_Integer::GetID() );
285 HYDROData_Iterator anIter( aDocument );
286 for ( ; anIter.More(); anIter.Next() )
288 Handle(HYDROData_Entity) anObject = anIter.Current();
289 if( anObject.IsNull() )
291 HYDROData_SequenceOfObjects aRefSeq = anObject->GetAllReferenceObjects();
292 for ( int i = 1, n = aRefSeq.Length(); i <= n; ++i )
294 Handle(HYDROData_Entity) aRefObject = aRefSeq.Value( i );
295 if( aRefObject->Label()==myLab )
296 anObject->Changed( theChangedGeometry );
301 bool HYDROData_Entity::IsMustBeUpdated( Geometry theGeom ) const
303 return ( ( GetGeomChangeFlag() & theGeom ) != 0 );
306 bool HYDROData_Entity::CanBeUpdated() const
311 bool HYDROData_Entity::IsRemoved() const
313 return !myLab.HasAttribute();
316 void HYDROData_Entity::Remove()
318 return myLab.ForgetAllAttributes( true );
321 bool HYDROData_Entity::CanRemove()
326 HYDROData_Entity::HYDROData_Entity( Geometry theGeom )
331 HYDROData_Entity::~HYDROData_Entity()
335 void HYDROData_Entity::CopyTo( const Handle(HYDROData_Entity)& theDestination,
336 bool isGenerateNewName ) const
338 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
339 if ( aDocument.IsNull() ) {
343 TDF_CopyLabel aCopy(myLab, theDestination->Label());
346 if( isGenerateNewName )
348 // generate a new unique name for the clone object:
349 // case 1: Image_1 -> Image_2
350 // case 2: ImageObj -> ImageObj_1
351 QString aName = theDestination->GetName();
352 QString aPrefix = aName;
353 if( aName.contains( '_' ) ) { // case 1
354 QString aSuffix = aName.section( '_', -1 );
355 bool anIsInteger = false;
356 aSuffix.toInt( &anIsInteger );
358 aPrefix = aName.section( '_', 0, -2 );
363 aName = HYDROData_Tool::GenerateObjectName( aDocument, aPrefix );
364 theDestination->SetName( aName );
368 Handle(HYDROData_Entity) HYDROData_Entity::GetFatherObject() const
370 Handle(HYDROData_Entity) aFather;
372 if ( !myLab.IsNull() )
374 TDF_Label aFatherLabel = myLab.Father();
376 while ( aFather.IsNull() && !aFatherLabel.IsNull() && !aFatherLabel.IsRoot() )
378 aFather = HYDROData_Iterator::Object( aFatherLabel );
379 aFatherLabel = aFatherLabel.Father();
386 HYDROData_SequenceOfObjects HYDROData_Entity::GetAllReferenceObjects() const
388 return HYDROData_SequenceOfObjects();
391 bool HYDROData_Entity::GetZLevel( Standard_Integer& theLevel ) const
395 TDF_Label aLabel = myLab.FindChild( DataTag_ZLevel, false );
396 if ( !aLabel.IsNull() )
398 Handle(TDataStd_Integer) anIntVal;
399 if ( aLabel.FindAttribute( TDataStd_Integer::GetID(), anIntVal ) )
401 theLevel = anIntVal->Get();
409 void HYDROData_Entity::SetZLevel( const Standard_Integer& theLevel )
411 Handle(TDataStd_Integer) A = TDataStd_Integer::Set( myLab.FindChild( DataTag_ZLevel ), theLevel );
412 A->SetID(TDataStd_Integer::GetID());
415 void HYDROData_Entity::RemoveZLevel()
417 TDF_Label aLabel = myLab.FindChild( DataTag_ZLevel, false );
418 if ( !aLabel.IsNull() )
419 aLabel.ForgetAllAttributes();
422 void HYDROData_Entity::SetLabel( const TDF_Label& theLabel )
427 void HYDROData_Entity::SaveByteArray( const int theTag,
431 TDF_Label aLab = theTag == 0 ? myLab : myLab.FindChild(theTag);
432 // array is empty, remove the attribute
434 aLab.ForgetAttribute(TDataStd_ByteArray::GetID());
437 // store data of image in byte array
438 Handle(TDataStd_ByteArray) aData;
439 if (!aLab.FindAttribute(TDataStd_ByteArray::GetID(), aData)) {
440 aData = TDataStd_ByteArray::Set(aLab, 1, theLen);
441 aData->SetID( TDataStd_ByteArray::GetID() );
443 Standard_Byte* Byte0 = &(aData->InternalArray()->ChangeArray1().ChangeFirst());
444 memcpy(Byte0, theData, theLen * sizeof (char));
445 // copy bytes one by one
446 if (aData->Length() != theLen) {
447 Handle(TColStd_HArray1OfByte) aNewData = new TColStd_HArray1OfByte(1, theLen);
448 for(int a = 0; a < theLen; a++)
449 aNewData->SetValue(a + 1, theData[a]);
450 aData->ChangeArray(aNewData);
454 // for(int a = 0; a < theLen; a++)
455 // aData->SetValue(a + 1, theData[a]);
459 const char* HYDROData_Entity::ByteArray(const int theTag, int& theLen) const
461 TDF_Label aLab = theTag == 0 ? myLab : myLab.FindChild(theTag);
462 Handle(TDataStd_ByteArray) aData;
463 if (!aLab.FindAttribute(TDataStd_ByteArray::GetID(), aData))
464 return NULL; // return empty image if there is no array
465 theLen = aData->Length();
467 return (const char*)(&(aData->InternalArray()->ChangeArray1().ChangeValue(1)));
471 int HYDROData_Entity::NbReferenceObjects( const int theTag ) const
473 Handle(TDataStd_ReferenceList) aRefs = getReferenceList( theTag, false );
474 return aRefs.IsNull() ? 0 : aRefs->Extent();
477 bool HYDROData_Entity::HasReference( const Handle(HYDROData_Entity)& theObj,
478 const int theTag ) const
480 if ( theObj.IsNull() )
483 Handle(TDataStd_ReferenceList) aRefs = getReferenceList( theTag, false );
484 if ( aRefs.IsNull() || aRefs->IsEmpty() )
487 TDF_ListIteratorOfLabelList aListIt( aRefs->List() );
488 for ( ; aListIt.More(); aListIt.Next() )
490 const TDF_Label& aRefLabel = aListIt.Value();
491 if ( theObj->Label() == aRefLabel )
498 void HYDROData_Entity::AddReferenceObject( const Handle(HYDROData_Entity)& theObj,
501 if ( theObj.IsNull() )
504 Handle(TDataStd_ReferenceList) aRefs = getReferenceList( theTag, true );
505 aRefs->Append( theObj->Label() );
506 aRefs->SetID(TDataStd_ReferenceList::GetID());
509 void HYDROData_Entity::SetReferenceObject( const Handle(HYDROData_Entity)& theObj,
513 if ( theObj.IsNull() )
515 RemoveReferenceObject( theTag, theIndex );
519 Handle(TDataStd_ReferenceList) aRefs = getReferenceList( theTag, true );
521 if ( theIndex >= aRefs->Extent() )
523 aRefs->Append( theObj->Label() );
525 else if ( theIndex < 0 )
527 aRefs->Prepend( theObj->Label() );
531 RemoveReferenceObject( theTag, theIndex );
533 Handle(HYDROData_Entity) aBeforeObj = GetReferenceObject( theTag, theIndex );
535 aRefs = getReferenceList( theTag, true ); // because reference list can be removed
536 if ( !aBeforeObj.IsNull() )
537 aRefs->InsertBefore( theObj->Label(), aBeforeObj->Label() );
539 aRefs->Append( theObj->Label() );
543 void HYDROData_Entity::InsertReferenceObject( const Handle(HYDROData_Entity)& theObj,
545 const int theBeforeIndex )
547 if ( theObj.IsNull() )
550 Handle(TDataStd_ReferenceList) aRefs = getReferenceList( theTag, true );
552 if ( theBeforeIndex >= aRefs->Extent() )
554 aRefs->Append( theObj->Label() );
556 else if ( theBeforeIndex < 0 )
558 aRefs->Prepend( theObj->Label() );
562 Handle(HYDROData_Entity) aBeforeObj = GetReferenceObject( theTag, theBeforeIndex );
563 if ( !aBeforeObj.IsNull() )
564 aRefs->InsertBefore( theObj->Label(), aBeforeObj->Label() );
566 aRefs->Append( theObj->Label() );
570 void HYDROData_Entity::SetReferenceObjects( const HYDROData_SequenceOfObjects& theObjects,
573 ClearReferenceObjects( theTag );
574 if ( theObjects.IsEmpty() )
577 HYDROData_SequenceOfObjects::Iterator anIter( theObjects );
578 for ( ; anIter.More(); anIter.Next() )
579 AddReferenceObject( anIter.Value(), theTag );
582 Handle(HYDROData_Entity) HYDROData_Entity::GetReferenceObject( const int theTag,
583 const int theIndex ) const
585 //DEBTRACE("GetReferenceObject " << theTag << " " << theIndex);
586 Handle(HYDROData_Entity) aRes;
588 Handle(TDataStd_ReferenceList) aRefs = getReferenceList( theTag, false );
589 if ( aRefs.IsNull() || theIndex < 0 || theIndex >= aRefs->Extent() )
592 TDF_ListIteratorOfLabelList anIter( aRefs->List() );
593 for ( int anIndex = 0; anIndex != theIndex && anIter.More(); anIter.Next(), ++anIndex );
595 const TDF_Label& aRefLabel = anIter.Value();
596 aRes = HYDROData_Iterator::Object( aRefLabel );
601 HYDROData_SequenceOfObjects HYDROData_Entity::GetReferenceObjects( const int theTag ) const
603 HYDROData_SequenceOfObjects aRes;
605 Handle(TDataStd_ReferenceList) aRefs = getReferenceList( theTag, false );
606 if ( aRefs.IsNull() )
609 TDF_ListIteratorOfLabelList anIter( aRefs->List() );
610 for ( ; anIter.More(); anIter.Next() )
612 const TDF_Label& aRefLabel = anIter.Value();
614 Handle(HYDROData_Entity) aRefObject = HYDROData_Iterator::Object( aRefLabel );
615 if ( aRefObject.IsNull() )
618 aRes.Append( aRefObject );
624 void HYDROData_Entity::RemoveReferenceObject( const TDF_Label& theRefLabel,
627 Handle(TDataStd_ReferenceList) aRefs = getReferenceList( theTag, false );
628 if ( aRefs.IsNull() )
631 if ( aRefs->Extent() == 1 )
633 // remove all if only one
634 ClearReferenceObjects( theTag );
638 aRefs->Remove( theRefLabel );
641 void HYDROData_Entity::RemoveReferenceObject( const int theTag,
644 Handle(TDataStd_ReferenceList) aRefs = getReferenceList( theTag, false );
645 if ( aRefs.IsNull() )
648 if ( aRefs->Extent() == 1 && theIndex == 0 )
650 // remove all if only one
651 ClearReferenceObjects( theTag );
656 TDF_ListIteratorOfLabelList anIter( aRefs->List() );
657 for ( ; anIndex != theIndex && anIter.More(); anIter.Next(), ++anIndex );
659 if ( anIndex != theIndex || !anIter.More() )
662 const TDF_Label& aRefLabel = anIter.Value();
663 aRefs->Remove( aRefLabel );
666 void HYDROData_Entity::ClearReferenceObjects( const int theTag )
668 TDF_Label aSetLabel = theTag == 0 ? myLab : myLab.FindChild( theTag );
669 aSetLabel.ForgetAttribute( TDataStd_ReferenceList::GetID() );
672 Handle(TDataStd_ReferenceList) HYDROData_Entity::getReferenceList( const int theTag,
673 const bool theIsCreate ) const
675 //DEBTRACE("getReferenceList " << theTag << " " << theIsCreate);
676 TDF_Label aLabel = theTag == 0 ? myLab : myLab.FindChild( theTag );
678 Handle(TDataStd_ReferenceList) aRefs;
679 if ( !aLabel.FindAttribute( TDataStd_ReferenceList::GetID(), aRefs ) && theIsCreate )
681 aRefs = TDataStd_ReferenceList::Set( aLabel );
682 aRefs->SetID(TDataStd_ReferenceList::GetID());
687 void HYDROData_Entity::SetColor( const QColor& theColor,
690 TDF_Label aLabel = theTag == 0 ? myLab : myLab.FindChild( theTag );
692 Handle(TDataStd_IntegerArray) aColorArray;
693 if ( !aLabel.FindAttribute( TDataStd_IntegerArray::GetID(), aColorArray ) )
695 aColorArray = TDataStd_IntegerArray::Set( aLabel, 1, 4 );
696 aColorArray->SetID(TDataStd_IntegerArray::GetID());
699 aColorArray->SetValue( 1, theColor.red() );
700 aColorArray->SetValue( 2, theColor.green() );
701 aColorArray->SetValue( 3, theColor.blue() );
702 aColorArray->SetValue( 4, theColor.alpha() );
705 QColor HYDROData_Entity::GetColor( const QColor& theDefColor,
706 const int theTag ) const
708 QColor aResColor = theDefColor;
710 TDF_Label aLabel = theTag == 0 ? myLab : myLab.FindChild( theTag );
712 Handle(TDataStd_IntegerArray) aColorArray;
713 if ( aLabel.FindAttribute( TDataStd_IntegerArray::GetID(), aColorArray ) )
715 aResColor.setRed( aColorArray->Value( 1 ) );
716 aResColor.setGreen( aColorArray->Value( 2 ) );
717 aResColor.setBlue( aColorArray->Value( 3 ) );
718 aResColor.setAlpha( aColorArray->Value( 4 ) );
724 bool HYDROData_Entity::GetColor( QColor& theOutColor,
725 const int theTag ) const
727 TDF_Label aLabel = theTag == 0 ? myLab : myLab.FindChild( theTag );
729 Handle(TDataStd_IntegerArray) aColorArray;
730 if ( aLabel.FindAttribute( TDataStd_IntegerArray::GetID(), aColorArray ) )
732 theOutColor.setRed( aColorArray->Value( 1 ) );
733 theOutColor.setGreen( aColorArray->Value( 2 ) );
734 theOutColor.setBlue( aColorArray->Value( 3 ) );
735 theOutColor.setAlpha( aColorArray->Value( 4 ) );
743 QStringList HYDROData_Entity::dumpObjectCreation( MapOfTreatedObjects& theTreatedObjects ) const
745 QStringList aResList;
747 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
748 if ( aDocument.IsNull() )
751 QString aDocName = aDocument->GetDocPyName();
752 QString aName = GetObjPyName();
754 aResList << QString( "%1 = %2.CreateObject( %3 )" )
755 .arg( aName ).arg( aDocName ).arg( getPyTypeID() );
756 aResList << QString( "%1.SetName( \"%2\" )" )
757 .arg( aName ).arg( GetName() );
758 aResList << QString( "" );
762 // Dump object z-level in viewer
763 Standard_Integer anObjZLevel = -1;
764 if ( GetZLevel( anObjZLevel ) )
766 aResList << QString( "%1.SetZLevel( %2 )" )
767 .arg( aName ).arg( anObjZLevel );
768 aResList << QString( "" );
775 QString HYDROData_Entity::getPyTypeID() const
777 //DEBTRACE("HYDROData_Entity::getPyTypeID " << GetKind());
780 case KIND_IMAGE: return "KIND_IMAGE";
781 case KIND_POLYLINE: return "KIND_POLYLINE";
782 case KIND_BATHYMETRY: return "KIND_BATHYMETRY";
783 case KIND_ALTITUDE: return "KIND_ALTITUDE";
784 case KIND_IMMERSIBLE_ZONE: return "KIND_IMMERSIBLE_ZONE";
785 case KIND_RIVER: return "KIND_RIVER";
786 case KIND_STREAM: return "KIND_STREAM";
787 case KIND_CONFLUENCE: return "KIND_CONFLUENCE";
788 case KIND_CHANNEL: return "KIND_CHANNEL";
789 case KIND_OBSTACLE: return "KIND_OBSTACLE";
790 case KIND_DIGUE: return "KIND_DIGUE";
791 case KIND_PROFILE: return "KIND_PROFILE";
792 case KIND_PROFILEUZ: return "KIND_PROFILEUZ";
793 case KIND_POLYLINEXY: return "KIND_POLYLINEXY";
794 case KIND_CALCULATION: return "KIND_CALCULATION";
795 case KIND_ZONE: return "KIND_ZONE";
796 case KIND_REGION: return "KIND_REGION";
797 case KIND_VISUAL_STATE: return "KIND_VISUAL_STATE";
798 case KIND_ARTIFICIAL_OBJECT: return "KIND_ARTIFICIAL_OBJECT";
799 case KIND_NATURAL_OBJECT: return "KIND_NATURAL_OBJECT";
800 case KIND_DUMMY_3D: return "KIND_DUMMY_3D";
801 case KIND_SHAPES_GROUP: return "KIND_SHAPES_GROUP";
802 case KIND_SPLIT_GROUP: return "KIND_SPLIT_GROUP";
803 case KIND_STREAM_ALTITUDE: return "KIND_STREAM_ALTITUDE";
804 case KIND_OBSTACLE_ALTITUDE: return "KIND_OBSTACLE_ALTITUDE";
805 case KIND_STRICKLER_TABLE: return "KIND_STRICKLER_TABLE";
806 case KIND_LAND_COVER_OBSOLETE: return "";
807 case KIND_CHANNEL_ALTITUDE: return "KIND_CHANNEL_ALTITUDE";
808 case KIND_LAND_COVER_MAP: return "KIND_LAND_COVER_MAP";
809 case KIND_BC_POLYGON: return "KIND_BC_POLYGON";
810 default: return "KIND_UNKNOWN"; ///! Unrecognized object
814 void HYDROData_Entity::setPythonReferenceObject( const QString& thePyScriptPath,
815 MapOfTreatedObjects& theTreatedObjects,
816 QStringList& theScript,
817 const Handle(HYDROData_Entity)& theRefObject,
818 const QString& theMethod ) const
820 if ( !checkObjectPythonDefinition( thePyScriptPath, theTreatedObjects, theScript, theRefObject ) )
823 QString aRefObjName = theRefObject->GetObjPyName();
825 QString anObjName = GetObjPyName();
826 theScript << QString( "%1.%2( %3 )" )
827 .arg( anObjName ).arg( theMethod ).arg( aRefObjName );
830 bool HYDROData_Entity::checkObjectPythonDefinition( const QString& thePyScriptPath,
831 MapOfTreatedObjects& theTreatedObjects,
832 QStringList& theScript,
833 const Handle(HYDROData_Entity)& theRefObject ) const
835 if ( theRefObject.IsNull() )
838 QString aRefObjName = theRefObject->GetName();
839 if ( aRefObjName.isEmpty() )
842 if ( theTreatedObjects.contains( aRefObjName ) )
845 // The definition of reference object must be dumped before this
846 QStringList aRefObjDump = theRefObject->DumpToPython( thePyScriptPath, theTreatedObjects );
847 if ( aRefObjDump.isEmpty() )
850 QStringList aTmpList = theScript;
851 theScript = aRefObjDump;
853 theScript << QString( "" );
854 theScript << aTmpList;
856 theTreatedObjects.insert( aRefObjName, theRefObject );
861 void HYDROData_Entity::setPythonObjectColor( QStringList& theScript,
862 const QColor& theColor,
863 const QColor& theDefaultColor,
864 const QString& theMethod ) const
866 if ( theColor == theDefaultColor )
867 return; //Do not set the color for object if it like default
869 QString anObjName = GetObjPyName();
870 theScript << QString( "%1.%2( QColor( %3, %4, %5, %6 ) )" )
871 .arg( anObjName ).arg( theMethod )
872 .arg( theColor.red() ).arg( theColor.green() )
873 .arg( theColor.blue() ).arg( theColor.alpha() );
876 void HYDROData_Entity::findPythonReferenceObject( QStringList& theScript,
877 QString defName) const
879 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
880 if ( aDocument.IsNull() )
883 if (defName.isEmpty())
884 theScript << QString( "%1 = %2.FindObjectByName( \"%3\" )" ).arg( GetObjPyName() )
885 .arg( aDocument->GetDocPyName() )
886 .arg( GetDefaultName() );
888 theScript << QString( "%1 = %2.FindObjectByName( \"%3\" )" ).arg( GetObjPyName() )
889 .arg( aDocument->GetDocPyName() )
893 void HYDROData_Entity::SetNameInDumpPython(QStringList& theScript,
894 QString theName) const
896 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
897 if ( aDocument.IsNull() )
900 if (theName.isEmpty())
901 theScript << QString( "%1.SetName( \"%2\" )" ).arg( GetObjPyName() )
904 theScript << QString( "%1.SetName( \"%2\" )" ).arg( GetObjPyName() )
908 void HYDROData_Entity::SetShape( int theTag, const TopoDS_Shape& theShape )
910 TNaming_Builder aBuilder( myLab.FindChild( theTag ) );
911 aBuilder.Generated( theShape );
912 aBuilder.NamedShape()->SetID(TNaming_NamedShape::GetID());
915 TopoDS_Shape HYDROData_Entity::GetShape( int theTag ) const
917 TDF_Label aShapeLabel = myLab.FindChild( theTag, false );
918 if ( !aShapeLabel.IsNull() )
920 Handle(TNaming_NamedShape) aNamedShape;
921 if ( aShapeLabel.FindAttribute( TNaming_NamedShape::GetID(), aNamedShape ) )
922 return aNamedShape->Get();
924 return TopoDS_Shape();
927 void HYDROData_Entity::SetDouble( int theTag, double theValue )
929 Handle(TDataStd_Real) anAttr;
930 TDF_Label aLabel = myLab.FindChild( theTag );
931 if( !aLabel.FindAttribute( TDataStd_Real::GetID(), anAttr ) )
933 anAttr = new TDataStd_Real();
934 anAttr->SetID(TDataStd_Real::GetID());
935 aLabel.AddAttribute( anAttr );
937 anAttr->Set( theValue );
940 double HYDROData_Entity::GetDouble( int theTag, double theDefValue ) const
942 Handle(TDataStd_Real) anAttr;
943 TDF_Label aLabel = myLab.FindChild( theTag );
944 if( !aLabel.FindAttribute( TDataStd_Real::GetID(), anAttr ) )
947 return anAttr->Get();
950 void HYDROData_Entity::SetInteger( int theTag, int theValue )
952 Handle(TDataStd_Integer) anAttr;
953 TDF_Label aLabel = myLab.FindChild( theTag );
954 if( !aLabel.FindAttribute( TDataStd_Integer::GetID(), anAttr ) )
956 anAttr = new TDataStd_Integer();
957 anAttr->SetID(TDataStd_Integer::GetID());
958 aLabel.AddAttribute(anAttr);
960 anAttr->Set( theValue );
963 int HYDROData_Entity::GetInteger( int theTag, int theDefValue ) const
965 Handle(TDataStd_Integer) anAttr;
966 TDF_Label aLabel = myLab.FindChild( theTag );
967 if( !aLabel.FindAttribute( TDataStd_Integer::GetID(), anAttr ) )
970 return anAttr->Get();
973 bool HYDROData_Entity::CompareLabels(const Handle(HYDROData_Entity)& theOtherObj)
975 if ( !theOtherObj.IsNull() )
976 return this->Label() == theOtherObj->Label();