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_Document.h>
20 #include <HYDROData_Application.h>
21 #include <HYDROData_Iterator.h>
22 #include <HYDROData_Tool.h>
23 #include <HYDROData_InterpolatorsFactory.h>
24 #include <HYDROData_StricklerTable.h>
25 #include <HYDROData_LandCoverMap.h>
27 #include <TDataStd_Real.hxx>
28 #include <TDataStd_Integer.hxx>
29 #include <TDataXtd_Position.hxx>
31 #include <TDF_Delta.hxx>
36 #include <QStringList>
37 #include <QTextStream>
40 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Document,MMgt_TShared)
42 #define PYTHON_DOC_NAME "hydro_doc"
44 static const int UNDO_LIMIT = 10; // number of possible undo operations in the module
46 static const int TAG_PROPS = 1; // general properties tag
47 static const int TAG_PROPS_NEW_ID = 1; // general properties: tag for storage of the new object ID
48 static const int TAG_OBJECTS = 2; // tag of the objects sub-tree
49 static const int TAG_HISTORY = 3; // tag of the history sub-tree (Root for History)
50 static const int TAG_LOCAL_CS = 4; // tag of local coordinate system information
51 static const int TAG_DEF_STRICKLER_COEFF = 5; // tag of default strickler coefficient
52 static const int TAG_COUNT_QUADTREE = 6; // tag of number of quadtrees created so far
53 static const int TAG_COUNT_DELAUNAY = 7; // tag of number of Delaunay triangulations created so far
54 static const gp_Pnt2d DEFAULT_LOCAL_CS( 0, 0 );
58 typedef QMap<Standard_Integer, Handle(HYDROData_Entity)> MapOfOrdered;
59 typedef QMap<QString, Handle(HYDROData_Entity)> MapOfUnordered;
61 Handle(HYDROData_Document) HYDROData_Document::Document(const int theStudyID)
63 Handle(HYDROData_Document) aResult =
64 HYDROData_Application::GetApplication()->GetDocument(theStudyID);
65 if (aResult.IsNull()) {
66 aResult = new HYDROData_Document();
67 HYDROData_Application::GetApplication()->AddDocument(theStudyID, aResult);
72 Handle(HYDROData_Document) HYDROData_Document::Document(
73 const TDF_Label& theObjectLabel )
75 Handle(HYDROData_Document) aResDoc;
76 if ( theObjectLabel.IsNull() )
79 Handle(TDocStd_Document) anObjDoc;
82 anObjDoc = TDocStd_Document::Get( theObjectLabel );
88 if ( anObjDoc.IsNull() )
91 HYDROData_Application* anApp = HYDROData_Application::GetApplication();
93 DataMapOfStudyIDDocument::Iterator aMapIt( anApp->myDocuments );
94 for ( ; aMapIt.More(); aMapIt.Next() )
96 Handle(HYDROData_Document) anAppDoc = aMapIt.Value();
97 if ( anAppDoc.IsNull() || anAppDoc->myDoc != anObjDoc )
107 bool HYDROData_Document::HasDocument(const int theStudyID)
109 Handle(HYDROData_Document) aResult =
110 HYDROData_Application::GetApplication()->GetDocument(theStudyID);
111 return !aResult.IsNull();
114 bool HYDROData_Document::DocumentId(const Handle(HYDROData_Document)& theDocument,
117 return HYDROData_Application::GetApplication()->GetDocumentId(theDocument, theDocId);
120 Data_DocError HYDROData_Document::Load(const char* theFileName, const int theStudyID)
122 Handle(TDocStd_Document) aResult;
123 TCollection_ExtendedString aPath ((const Standard_CString)theFileName);
124 PCDM_ReaderStatus aStatus = (PCDM_ReaderStatus) -1;
127 aStatus = HYDROData_Application::GetApplication()->Open (aPath, aResult);
129 catch (Standard_Failure)
131 if (!aResult.IsNull()) {
132 aResult->SetUndoLimit(UNDO_LIMIT);
133 HYDROData_Application::GetApplication()->AddDocument(theStudyID, new HYDROData_Document(aResult));
136 Data_DocError anError;
139 anError = DocError_OK;
141 case PCDM_RS_NoDriver:
142 case PCDM_RS_UnknownFileDriver:
143 case PCDM_RS_NoSchema:
144 case PCDM_RS_DriverFailure:
145 case PCDM_RS_WrongResource:
146 anError = DocError_ResourcesProblem;
148 case PCDM_RS_OpenError:
149 case PCDM_RS_NoDocument:
150 case PCDM_RS_WrongStreamMode:
151 case PCDM_RS_PermissionDenied:
152 anError = DocError_CanNotOpen;
154 case PCDM_RS_NoVersion:
155 anError = DocError_InvalidVersion;
157 case PCDM_RS_ExtensionFailure:
158 case PCDM_RS_FormatFailure:
159 case PCDM_RS_TypeFailure:
160 case PCDM_RS_TypeNotFoundInSchema:
161 case PCDM_RS_UnrecognizedFileFormat:
162 anError = DocError_InvalidFormat;
164 case PCDM_RS_MakeFailure:
166 anError = DocError_UnknownProblem;
172 Data_DocError HYDROData_Document::Save(const char* theFileName)
174 TCollection_ExtendedString aPath ((const Standard_CString)theFileName);
175 PCDM_StoreStatus aStatus;
177 aStatus = HYDROData_Application::GetApplication()->SaveAs (myDoc, aPath);
179 catch (Standard_Failure) {}
180 myTransactionsAfterSave = 0;
181 Standard::Purge(); // Release free memory
184 Data_DocError anError;
187 anError = DocError_OK;
189 case PCDM_SS_DriverFailure:
190 anError = DocError_ResourcesProblem;
192 case PCDM_SS_WriteFailure:
193 //case PCDM_SS_DiskWritingFailure:
194 //case PCDM_SS_UserRightsFailure:
195 anError = DocError_CanNotOpen;
198 anError = DocError_UnknownProblem;
204 void HYDROData_Document::Close()
207 HYDROData_Application::GetApplication()->RemoveDocument(this);
210 double HYDROData_Document::GetDefaultStricklerCoefficient() const
213 TDF_Label aLabel = myDoc->Main().FindChild(TAG_DEF_STRICKLER_COEFF, Standard_False);
214 if ( !aLabel.IsNull() )
216 Handle(TDataStd_Real) anAttr;
217 if ( aLabel.FindAttribute( TDataStd_Real::GetID(), anAttr ) )
218 aRes = anAttr->Get();
224 void HYDROData_Document::SetDefaultStricklerCoefficient( double theCoeff ) const
226 TDF_Label aLabel = myDoc->Main().FindChild(TAG_DEF_STRICKLER_COEFF);
227 if ( !aLabel.IsNull() )
229 Handle(TDataStd_Real) anAttr;
230 if ( !aLabel.FindAttribute( TDataStd_Real::GetID(), anAttr ) )
232 anAttr = new TDataStd_Real();
233 aLabel.AddAttribute(anAttr);
234 anAttr->SetID(TDataStd_Real::GetID());
236 anAttr->Set( theCoeff );
240 int HYDROData_Document::GetCountQuadtree() const
243 TDF_Label aLabel = myDoc->Main().FindChild(TAG_COUNT_QUADTREE, Standard_False);
244 if ( !aLabel.IsNull() )
246 Handle(TDataStd_Integer) anAttr;
247 if ( aLabel.FindAttribute( TDataStd_Integer::GetID(), anAttr ) )
248 nbQuad = anAttr->Get();
253 void HYDROData_Document::SetCountQuadtree( int nbQuad) const
255 TDF_Label aLabel = myDoc->Main().FindChild(TAG_COUNT_QUADTREE);
256 if ( !aLabel.IsNull() )
258 Handle(TDataStd_Integer) anAttr;
259 if ( !aLabel.FindAttribute( TDataStd_Integer::GetID(), anAttr ) )
261 anAttr = new TDataStd_Integer();
262 aLabel.AddAttribute(anAttr);
263 anAttr->SetID(TDataStd_Integer::GetID());
265 anAttr->Set( nbQuad );
269 int HYDROData_Document::GetCountDelaunay() const
272 TDF_Label aLabel = myDoc->Main().FindChild(TAG_COUNT_DELAUNAY, Standard_False);
273 if ( !aLabel.IsNull() )
275 Handle(TDataStd_Integer) anAttr;
276 if ( aLabel.FindAttribute( TDataStd_Integer::GetID(), anAttr ) )
277 nbDelaunay = anAttr->Get();
282 void HYDROData_Document::SetCountDelaunay( int nbDelaunay) const
284 TDF_Label aLabel = myDoc->Main().FindChild(TAG_COUNT_DELAUNAY);
285 if ( !aLabel.IsNull() )
287 Handle(TDataStd_Integer) anAttr;
288 if ( !aLabel.FindAttribute( TDataStd_Integer::GetID(), anAttr ) )
290 anAttr = new TDataStd_Integer();
291 aLabel.AddAttribute(anAttr);
292 anAttr->SetID(TDataStd_Integer::GetID());
294 anAttr->Set( nbDelaunay );
298 bool HYDROData_Document::DumpToPython( const QString& thePyScriptPath,
299 const bool theIsMultiFile ) const
301 // Try to open the file
302 QFile aFile( thePyScriptPath );
303 if ( !aFile.open( QIODevice::WriteOnly | QFile::Text ) )
306 MapOfTreatedObjects aTreatedObjects;
308 // Dump header for python script
309 QStringList aHeaderDump = DumpToPython( thePyScriptPath, aTreatedObjects, theIsMultiFile );
310 if ( aHeaderDump.isEmpty() )
313 HYDROData_Tool::WriteStringsToFile( aFile, aHeaderDump );
317 // Dump the local CS data to Python
319 QString aLCS = QString( "%1.SetLocalCS( %2, %3 )" ).arg( GetDocPyName() ).arg( myLX, 0, 'f', 3 ).arg( myLY, 0, 'f', 3 );
322 HYDROData_Tool::WriteStringsToFile( aFile, QStringList() << aLCS );
324 // Dump all model objects to Python script
325 aRes = aRes && dumpPartitionToPython( aFile, thePyScriptPath, theIsMultiFile, aTreatedObjects, KIND_IMAGE );
326 aRes = aRes && dumpPartitionToPython( aFile, thePyScriptPath, theIsMultiFile, aTreatedObjects, KIND_STRICKLER_TABLE );
327 aRes = aRes && dumpPartitionToPython( aFile, thePyScriptPath, theIsMultiFile, aTreatedObjects, KIND_POLYLINEXY );
328 aRes = aRes && dumpPartitionToPython( aFile, thePyScriptPath, theIsMultiFile, aTreatedObjects, KIND_BATHYMETRY );
329 aRes = aRes && dumpPartitionToPython( aFile, thePyScriptPath, theIsMultiFile, aTreatedObjects, KIND_PROFILE );
330 aRes = aRes && dumpPartitionToPython( aFile, thePyScriptPath, theIsMultiFile, aTreatedObjects, KIND_POLYLINE );
331 aRes = aRes && dumpPartitionToPython( aFile, thePyScriptPath, theIsMultiFile, aTreatedObjects, KIND_IMMERSIBLE_ZONE );
332 aRes = aRes && dumpPartitionToPython( aFile, thePyScriptPath, theIsMultiFile, aTreatedObjects, KIND_STREAM );
333 aRes = aRes && dumpPartitionToPython( aFile, thePyScriptPath, theIsMultiFile, aTreatedObjects, KIND_CHANNEL );
334 aRes = aRes && dumpPartitionToPython( aFile, thePyScriptPath, theIsMultiFile, aTreatedObjects, KIND_DIGUE );
335 aRes = aRes && dumpPartitionToPython( aFile, thePyScriptPath, theIsMultiFile, aTreatedObjects, KIND_OBSTACLE );
336 aRes = aRes && dumpPartitionToPython( aFile, thePyScriptPath, theIsMultiFile, aTreatedObjects, KIND_LAND_COVER_MAP );
337 aRes = aRes && dumpPartitionToPython( aFile, thePyScriptPath, theIsMultiFile, aTreatedObjects, KIND_CALCULATION );
339 // Dump code to close python fuction
340 if ( aRes && theIsMultiFile )
342 QStringList aFooterScript;
343 aFooterScript << QString( "" );
344 aFooterScript << QString( " pass" );
345 HYDROData_Tool::WriteStringsToFile( aFile, aFooterScript );
351 QString HYDROData_Document::GetDocPyName() const
353 QString aDocName = PYTHON_DOC_NAME;
357 if ( DocumentId( this, aDocId ) )
358 aDocName += "_" + QString::number( aDocId );
364 QStringList HYDROData_Document::DumpToPython( const QString& thePyScriptPath,
365 MapOfTreatedObjects& theTreatedObjects,
366 const bool theIsMultiFile ) const
368 QString aDocName = GetDocPyName();
370 // Append document in to the map of treated objects to prevent names overlaping
371 theTreatedObjects.insert( aDocName, this );
374 if ( !DocumentId( this, aDocId ) )
377 QStringList aResScript;
379 aResScript << QString( "from HYDROPy import *" );
380 aResScript << QString( "from PyQt5.QtCore import *" );
381 aResScript << QString( "from PyQt5.QtGui import *" );
383 if ( theIsMultiFile )
385 aResScript << QString( "import salome" );
386 aResScript << QString( "" );
387 aResScript << QString( "def RebuildData( theStudy ):" );
388 aResScript << QString( " %1 = HYDROData_Document.Document( theStudy._get_StudyId() )" ).arg( aDocName );
392 aResScript << QString( "" );
393 aResScript << QString( "%1 = HYDROData_Document.Document( theStudy._get_StudyId() )" ).arg( aDocName );
399 bool HYDROData_Document::dumpPartitionToPython( QFile& theFile,
400 const QString& thePyScriptPath,
401 const bool theIsMultiFile,
402 MapOfTreatedObjects& theTreatedObjects,
403 const ObjectKind& theObjectKind ) const
405 if ( !theFile.isOpen() )
408 QTextStream anOutStream( &theFile );
412 HYDROData_Iterator anIterator( this, theObjectKind );
413 for( ; anIterator.More(); anIterator.Next() )
415 Handle(HYDROData_Entity) anObject = anIterator.Current();
416 if ( anObject.IsNull() )
419 QString anObjName = anObject->GetName();
420 if ( theTreatedObjects.contains( anObjName ) )
423 theTreatedObjects.insert( anObjName, anObject );
425 QStringList anObjDump = anObject->DumpToPython( thePyScriptPath, theTreatedObjects );
427 if ( theIsMultiFile )
429 // For multifile dump we use the function, see the document dump header
430 QStringList::iterator anIt = anObjDump.begin();
431 for ( ; anIt != anObjDump.end(); ++anIt )
432 anIt->prepend( " " );
435 HYDROData_Tool::WriteStringsToFile( theFile, anObjDump );
441 bool takeLastDigits( QString& theStr, int& aRes )
446 for ( int i = theStr.length() - 1; i >= 0; --i )
448 const QChar& aChar = theStr.at( i );
449 if ( !aChar.isDigit() )
452 anStrNum.prepend( aChar );
455 if ( anStrNum.isEmpty() )
458 theStr.remove( theStr.length() - anStrNum.length(), anStrNum.length() );
459 aRes = anStrNum.toInt();
464 bool isObjectNameLessThan( const QString& theStr1, const QString& theStr2 )
466 QString aStr1 = theStr1, aStr2 = theStr2;
468 int aNum1 = -1, aNum2 = -1;
469 if ( takeLastDigits( aStr1, aNum1 ) && takeLastDigits( aStr2, aNum2 ) )
471 if ( aStr1 == aStr2 )
472 return aNum1 < aNum2;
475 return theStr1 < theStr2;
478 HYDROData_SequenceOfObjects HYDROData_Document::GetObjectsLayerOrder(
479 const Standard_Boolean theIsAll ) const
481 HYDROData_SequenceOfObjects anOrder;
483 MapOfOrdered aMapOfOrdered;
484 MapOfUnordered aMapOfUnordered;
486 HYDROData_Iterator anIter( this );
487 for ( ; anIter.More(); anIter.Next() )
489 Handle(HYDROData_Entity) anObject = anIter.Current();
490 if ( anObject.IsNull() || !anObject->IsHas2dPrs() )
493 Standard_Integer anObjZLevel = -1;
494 if ( anObject->GetZLevel( anObjZLevel ) )
496 aMapOfOrdered.insert( anObjZLevel, anObject );
500 QString anObjName = anObject->GetName();
501 if ( anObjName.isEmpty() )
504 aMapOfUnordered.insert( anObjName, anObject );
508 MapOfOrdered::const_iterator anOrderedMapIt = aMapOfOrdered.constBegin();
509 for ( ; anOrderedMapIt != aMapOfOrdered.constEnd(); anOrderedMapIt++ )
511 const Handle(HYDROData_Entity)& anObject = anOrderedMapIt.value();
512 anOrder.Prepend( anObject );
517 QStringList aSortedNames = aMapOfUnordered.keys();
518 qSort( aSortedNames.begin(), aSortedNames.end(), isObjectNameLessThan );
520 for ( int i = 0; i < aSortedNames.length(); ++i )
522 QString anObjName = aSortedNames.value( i );
524 const Handle(HYDROData_Entity)& anObject = aMapOfUnordered.value( anObjName );
525 anOrder.Append( anObject );
532 void HYDROData_Document::SetObjectsLayerOrder( const HYDROData_SequenceOfObjects& theOrder )
534 // At first we remove previous model order
535 RemoveObjectsLayerOrder();
537 // Make new objects order
538 Standard_Integer aLevel = 0;
539 for ( int i = theOrder.Length(), n = 1; i >= n; --i )
541 const Handle(HYDROData_Entity)& anObject = theOrder.Value( i );
542 if ( anObject.IsNull() || !anObject->IsHas2dPrs() )
545 anObject->SetZLevel( aLevel++ );
549 void HYDROData_Document::Show( const Handle(HYDROData_Entity)& theObject )
551 HYDROData_SequenceOfObjects anOrder;
552 anOrder.Append( theObject );
556 void HYDROData_Document::Show( const HYDROData_SequenceOfObjects& theObjects )
558 MapOfUnordered aMapOfUnordered;
560 for ( int i = 1, n = theObjects.Length(); i <= n; ++i )
562 const Handle(HYDROData_Entity)& anObject = theObjects.Value( i );
563 if ( anObject.IsNull() || !anObject->IsHas2dPrs() )
566 Standard_Integer anObjZLevel = -1;
567 if ( anObject->GetZLevel( anObjZLevel ) )
569 continue; // Skip objects that already have the z-level
573 QString anObjName = anObject->GetName();
574 if ( anObjName.isEmpty() )
577 aMapOfUnordered.insert( anObjName, anObject );
581 if ( aMapOfUnordered.isEmpty() )
582 return; // Nothing to show
584 Standard_Integer aTopId = 0;
586 HYDROData_SequenceOfObjects aModelOrder = GetObjectsLayerOrder( Standard_False );
587 if ( !aModelOrder.IsEmpty() )
589 const Handle(HYDROData_Entity)& anObject = aModelOrder.First();
590 anObject->GetZLevel( aTopId );
594 aTopId += aMapOfUnordered.size() - 1;
596 QStringList aSortedNames = aMapOfUnordered.keys();
597 qSort( aSortedNames.begin(), aSortedNames.end(), isObjectNameLessThan );
599 for ( int i = 0; i < aSortedNames.length(); ++i )
601 QString anObjName = aSortedNames.value( i );
603 const Handle(HYDROData_Entity)& anObject = aMapOfUnordered.value( anObjName );
604 anObject->SetZLevel( aTopId-- );
608 void HYDROData_Document::RemoveObjectsLayerOrder()
610 HYDROData_Iterator anIter( this );
611 for ( ; anIter.More(); anIter.Next() )
613 Handle(HYDROData_Entity) anObject = anIter.Current();
614 if ( anObject.IsNull() || !anObject->IsHas2dPrs() )
617 anObject->RemoveZLevel();
621 void HYDROData_Document::StartOperation()
626 void HYDROData_Document::CommitOperation(const TCollection_ExtendedString& theName)
628 if( !myDoc->CommitCommand() ) // it means that there were no modifications done
631 NewID(); // workaround: do something just to modify the document
632 myDoc->CommitCommand();
634 myTransactionsAfterSave++;
636 if( theName.Length() != 0 )
638 const TDF_DeltaList& aList = GetUndos();
639 if( !aList.IsEmpty() )
641 Handle(TDF_Delta) aDelta = aList.Last();
642 if( !aDelta.IsNull() )
643 aDelta->SetName( theName );
648 void HYDROData_Document::AbortOperation()
650 myDoc->AbortCommand();
653 bool HYDROData_Document::IsOperation()
655 return myDoc->HasOpenCommand() != 0;
658 bool HYDROData_Document::IsModified()
660 return myTransactionsAfterSave != 0;
663 bool HYDROData_Document::CanUndo()
665 return myDoc->GetAvailableUndos() > 0;
668 const TDF_DeltaList& HYDROData_Document::GetUndos()
670 return myDoc->GetUndos();
673 void HYDROData_Document::ClearUndos()
675 return myDoc->ClearUndos();
678 void HYDROData_Document::Undo()
681 myTransactionsAfterSave--;
684 bool HYDROData_Document::CanRedo()
686 return myDoc->GetAvailableRedos() > 0;
689 const TDF_DeltaList& HYDROData_Document::GetRedos()
691 return myDoc->GetRedos();
694 void HYDROData_Document::ClearRedos()
696 return myDoc->ClearRedos();
699 void HYDROData_Document::Redo()
702 myTransactionsAfterSave++;
705 Handle(HYDROData_Entity) HYDROData_Document::CreateObject( const ObjectKind theKind )
707 return HYDROData_Iterator::CreateObject( this, theKind );
710 Handle(HYDROData_Entity) HYDROData_Document::FindObjectByName(
711 const QString& theName,
712 const ObjectKind theObjectKind ) const
714 Handle(HYDROData_Entity) anObject;
715 if ( theName.isEmpty() )
718 QStringList aNamesList;
719 aNamesList << theName;
721 HYDROData_SequenceOfObjects aSeqOfObjs = FindObjectsByNames( aNamesList, theObjectKind );
722 if( aSeqOfObjs.IsEmpty() )
725 anObject = aSeqOfObjs.First();
729 HYDROData_SequenceOfObjects HYDROData_Document::FindObjectsByNames(
730 const QStringList& theNames,
731 const ObjectKind theObjectKind ) const
733 HYDROData_SequenceOfObjects aResSeq;
735 QStringList aNamesList = theNames;
737 HYDROData_Iterator anIter( this, theObjectKind );
738 for( ; anIter.More(); anIter.Next() )
740 Handle(HYDROData_Entity) anObject = anIter.Current();
741 if( anObject.IsNull() )
744 QString anObjName = anObject->GetName();
745 if ( anObjName.isEmpty() || !aNamesList.contains( anObjName ) )
748 aResSeq.Append( anObject );
750 aNamesList.removeAll( anObjName );
751 if ( aNamesList.isEmpty() )
758 HYDROData_SequenceOfObjects HYDROData_Document::CollectAllObjects( const ObjectKind theObjectKind ) const
760 HYDROData_SequenceOfObjects aResSeq;
761 HYDROData_Iterator anIter( this, theObjectKind );
762 for( ; anIter.More(); anIter.Next() )
764 Handle(HYDROData_Entity) anObject = anIter.Current();
765 if( anObject.IsNull() )
767 aResSeq.Append( anObject );
772 HYDROData_Document::HYDROData_Document()
774 HYDROData_Application::GetApplication()->NewDocument("BinOcaf", myDoc);
775 myDoc->SetUndoLimit(UNDO_LIMIT);
776 NewID(); // needed to have at least one attribute in initial document to avoid errors
777 myTransactionsAfterSave = 0;
781 myInterpolatorsFactory = 0;
784 HYDROData_Document::HYDROData_Document(const Handle(TDocStd_Document)& theDoc)
787 myTransactionsAfterSave = 0;
791 myInterpolatorsFactory = 0;
794 HYDROData_Document::~HYDROData_Document()
798 int HYDROData_Document::NewID()
800 TDF_Label anIDLab = myDoc->Main().FindChild(TAG_PROPS).
801 FindChild(TAG_PROPS_NEW_ID);
802 Handle(TDataStd_Integer) anInt;
803 if (!anIDLab.FindAttribute(TDataStd_Integer::GetID(), anInt)) {
804 anInt = TDataStd_Integer::Set(anIDLab, 0);
806 // just increment value and return
807 anInt->Set(anInt->Get() + 1);
811 TDF_Label HYDROData_Document::LabelOfObjects()
813 return myDoc->Main().FindChild(TAG_OBJECTS);
816 TDF_Label HYDROData_Document::LabelOfLocalCS() const
818 return myDoc->Main().FindChild(TAG_LOCAL_CS);
821 void HYDROData_Document::GetLocalCS( double& theLX, double& theLY ) const
823 TDF_Label aLocalCSLab = LabelOfLocalCS();
825 Handle( TDataXtd_Position ) aLocalCS;
826 if( aLocalCSLab.FindAttribute( TDataXtd_Position::GetID(), aLocalCS ) )
828 gp_Pnt aLocalCS3d = aLocalCS->GetPosition();
829 theLX = aLocalCS3d.X();
830 theLY = aLocalCS3d.Y();
834 theLX = DEFAULT_LOCAL_CS.X();
835 theLY = DEFAULT_LOCAL_CS.Y();
839 void HYDROData_Document::SetLocalCS( double theLX, double theLY )
843 // update the local CS data in attribute
844 TDF_Label aLocalCSLab = LabelOfLocalCS();
845 Handle( TDataXtd_Position ) aLocalCS;
846 if( !aLocalCSLab.FindAttribute( TDataXtd_Position::GetID(), aLocalCS ) )
847 aLocalCS = TDataXtd_Position::Set( aLocalCSLab );
849 gp_Pnt aLocalCS3d( theLX, theLY, 0 );
850 aLocalCS->SetPosition( aLocalCS3d );
852 // calculate delta for coordinates
853 double aDX = myLX - theLX;
854 double aDY = myLY - theLY;
856 // update the local CS data in internal fields
860 //update all objects in the document
861 HYDROData_Iterator anIterator( this, KIND_UNKNOWN );
862 for( ; anIterator.More(); anIterator.Next() )
863 anIterator.Current()->UpdateLocalCS( aDX, aDY );
866 void HYDROData_Document::UpdateLCSFields() const
868 if( myLX >= 0 && myLY >= 0 )
872 GetLocalCS( aLX, aLY );
873 HYDROData_Document* aThat = const_cast<HYDROData_Document*>( this );
878 void HYDROData_Document::Transform( double& X, double& Y, bool IsToLocalCS ) const
893 void HYDROData_Document::Transform( gp_Pnt& thePnt, bool IsToLocalCS ) const
895 double X = thePnt.X();
896 double Y = thePnt.Y();
897 double Z = thePnt.Z();
898 Transform( X, Y, IsToLocalCS );
899 thePnt = gp_Pnt( X, Y, Z );
902 void HYDROData_Document::Transform( gp_XYZ& thePnt, bool IsToLocalCS ) const
904 double X = thePnt.X();
905 double Y = thePnt.Y();
906 double Z = thePnt.Z();
907 Transform( X, Y, IsToLocalCS );
908 thePnt = gp_XYZ( X, Y, Z );
911 void HYDROData_Document::Transform( double& X, double& Y, double& Z, bool IsToLocalCS ) const
913 Transform( X, Y, IsToLocalCS );
916 void HYDROData_Document::Transform( gp_XY& thePnt, bool IsToLocalCS ) const
918 double X = thePnt.X();
919 double Y = thePnt.Y();
920 Transform( X, Y, IsToLocalCS );
921 thePnt = gp_XY( X, Y );
924 HYDROData_InterpolatorsFactory* HYDROData_Document::GetInterpolatorsFactory()
926 if ( !myInterpolatorsFactory ) {
927 myInterpolatorsFactory = new HYDROData_InterpolatorsFactory();
930 return myInterpolatorsFactory;
933 HYDROData_IProfilesInterpolator* HYDROData_Document::GetInterpolator( const TCollection_AsciiString& theName ) const
935 HYDROData_IProfilesInterpolator* anInterpolator = NULL;
937 HYDROData_Document* aThat = const_cast<HYDROData_Document*>( this );
938 HYDROData_InterpolatorsFactory* aFactory = aThat->GetInterpolatorsFactory();
940 anInterpolator = aFactory->GetInterpolator( theName );
943 return anInterpolator;
946 NCollection_Sequence<TCollection_AsciiString> HYDROData_Document::GetInterpolatorNames() const
948 NCollection_Sequence<TCollection_AsciiString> aNames;
950 HYDROData_Document* aThat = const_cast<HYDROData_Document*>( this );
951 HYDROData_InterpolatorsFactory* aFactory = aThat->GetInterpolatorsFactory();
953 aNames = aFactory->GetInterpolatorNames();
959 QColor HYDROData_Document::GetAssociatedColor( const QString& theStricklerType, const Handle(HYDROData_StricklerTable)& theTable ) const
961 if( !theTable.IsNull() && theTable->HasType( theStricklerType ) )
962 return theTable->GetColor( theStricklerType );
964 HYDROData_Iterator anIt( this, KIND_STRICKLER_TABLE );
965 for( ; anIt.More(); anIt.Next() )
967 Handle(HYDROData_StricklerTable) aTable = Handle(HYDROData_StricklerTable)::DownCast( anIt.Current() );
968 if( aTable->HasType( theStricklerType ) )
969 return aTable->GetColor( theStricklerType );
974 void HYDROData_Document::CollectQGISValues( const QString& theAttrName,
975 QStringList& theAttrValues,
976 QStringList& theStricklerTypes ) const
978 HYDROData_Iterator It( this, KIND_STRICKLER_TABLE );
979 for( ; It.More(); It.Next() )
981 Handle(HYDROData_StricklerTable) aTable = Handle(HYDROData_StricklerTable)::DownCast( It.Current() );
982 if( !aTable.IsNull() && aTable->GetAttrName()==theAttrName )
984 theAttrValues.clear();
985 theStricklerTypes = aTable->GetTypes();
986 foreach( QString aType, theStricklerTypes )
988 QString anAttrValue = aTable->GetAttrValue( aType );
989 theAttrValues.append( anAttrValue );