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_BC_POLYGON );
338 aRes = aRes && dumpPartitionToPython( aFile, thePyScriptPath, theIsMultiFile, aTreatedObjects, KIND_CALCULATION );
340 // Dump code to close python fuction
341 if ( aRes && theIsMultiFile )
343 QStringList aFooterScript;
344 aFooterScript << QString( "" );
345 aFooterScript << QString( " pass" );
346 HYDROData_Tool::WriteStringsToFile( aFile, aFooterScript );
352 QString HYDROData_Document::GetDocPyName() const
354 QString aDocName = PYTHON_DOC_NAME;
358 if ( DocumentId( this, aDocId ) )
359 aDocName += "_" + QString::number( aDocId );
365 QStringList HYDROData_Document::DumpToPython( const QString& thePyScriptPath,
366 MapOfTreatedObjects& theTreatedObjects,
367 const bool theIsMultiFile ) const
369 QString aDocName = GetDocPyName();
371 // Append document in to the map of treated objects to prevent names overlaping
372 theTreatedObjects.insert( aDocName, this );
375 if ( !DocumentId( this, aDocId ) )
378 QStringList aResScript;
380 aResScript << QString( "from HYDROPy import *" );
381 aResScript << QString( "from PyQt5.QtCore import *" );
382 aResScript << QString( "from PyQt5.QtGui import *" );
384 if ( theIsMultiFile )
386 aResScript << QString( "import salome" );
387 aResScript << QString( "" );
388 aResScript << QString( "def RebuildData( theStudy ):" );
389 aResScript << QString( " %1 = HYDROData_Document.Document( theStudy._get_StudyId() )" ).arg( aDocName );
393 aResScript << QString( "" );
394 aResScript << QString( "%1 = HYDROData_Document.Document( theStudy._get_StudyId() )" ).arg( aDocName );
400 bool HYDROData_Document::dumpPartitionToPython( QFile& theFile,
401 const QString& thePyScriptPath,
402 const bool theIsMultiFile,
403 MapOfTreatedObjects& theTreatedObjects,
404 const ObjectKind& theObjectKind ) const
406 if ( !theFile.isOpen() )
409 QTextStream anOutStream( &theFile );
413 HYDROData_Iterator anIterator( this, theObjectKind );
414 for( ; anIterator.More(); anIterator.Next() )
416 Handle(HYDROData_Entity) anObject = anIterator.Current();
417 if ( anObject.IsNull() )
420 QString anObjName = anObject->GetName();
421 if ( theTreatedObjects.contains( anObjName ) )
424 theTreatedObjects.insert( anObjName, anObject );
426 QStringList anObjDump = anObject->DumpToPython( thePyScriptPath, theTreatedObjects );
428 if ( theIsMultiFile )
430 // For multifile dump we use the function, see the document dump header
431 QStringList::iterator anIt = anObjDump.begin();
432 for ( ; anIt != anObjDump.end(); ++anIt )
433 anIt->prepend( " " );
436 HYDROData_Tool::WriteStringsToFile( theFile, anObjDump );
442 bool takeLastDigits( QString& theStr, int& aRes )
447 for ( int i = theStr.length() - 1; i >= 0; --i )
449 const QChar& aChar = theStr.at( i );
450 if ( !aChar.isDigit() )
453 anStrNum.prepend( aChar );
456 if ( anStrNum.isEmpty() )
459 theStr.remove( theStr.length() - anStrNum.length(), anStrNum.length() );
460 aRes = anStrNum.toInt();
465 bool isObjectNameLessThan( const QString& theStr1, const QString& theStr2 )
467 QString aStr1 = theStr1, aStr2 = theStr2;
469 int aNum1 = -1, aNum2 = -1;
470 if ( takeLastDigits( aStr1, aNum1 ) && takeLastDigits( aStr2, aNum2 ) )
472 if ( aStr1 == aStr2 )
473 return aNum1 < aNum2;
476 return theStr1 < theStr2;
479 HYDROData_SequenceOfObjects HYDROData_Document::GetObjectsLayerOrder(
480 const Standard_Boolean theIsAll ) const
482 HYDROData_SequenceOfObjects anOrder;
484 MapOfOrdered aMapOfOrdered;
485 MapOfUnordered aMapOfUnordered;
487 HYDROData_Iterator anIter( this );
488 for ( ; anIter.More(); anIter.Next() )
490 Handle(HYDROData_Entity) anObject = anIter.Current();
491 if ( anObject.IsNull() || !anObject->IsHas2dPrs() )
494 Standard_Integer anObjZLevel = -1;
495 if ( anObject->GetZLevel( anObjZLevel ) )
497 aMapOfOrdered.insert( anObjZLevel, anObject );
501 QString anObjName = anObject->GetName();
502 if ( anObjName.isEmpty() )
505 aMapOfUnordered.insert( anObjName, anObject );
509 MapOfOrdered::const_iterator anOrderedMapIt = aMapOfOrdered.constBegin();
510 for ( ; anOrderedMapIt != aMapOfOrdered.constEnd(); anOrderedMapIt++ )
512 const Handle(HYDROData_Entity)& anObject = anOrderedMapIt.value();
513 anOrder.Prepend( anObject );
518 QStringList aSortedNames = aMapOfUnordered.keys();
519 qSort( aSortedNames.begin(), aSortedNames.end(), isObjectNameLessThan );
521 for ( int i = 0; i < aSortedNames.length(); ++i )
523 QString anObjName = aSortedNames.value( i );
525 const Handle(HYDROData_Entity)& anObject = aMapOfUnordered.value( anObjName );
526 anOrder.Append( anObject );
533 void HYDROData_Document::SetObjectsLayerOrder( const HYDROData_SequenceOfObjects& theOrder )
535 // At first we remove previous model order
536 RemoveObjectsLayerOrder();
538 // Make new objects order
539 Standard_Integer aLevel = 0;
540 for ( int i = theOrder.Length(), n = 1; i >= n; --i )
542 const Handle(HYDROData_Entity)& anObject = theOrder.Value( i );
543 if ( anObject.IsNull() || !anObject->IsHas2dPrs() )
546 anObject->SetZLevel( aLevel++ );
550 void HYDROData_Document::Show( const Handle(HYDROData_Entity)& theObject )
552 HYDROData_SequenceOfObjects anOrder;
553 anOrder.Append( theObject );
557 void HYDROData_Document::Show( const HYDROData_SequenceOfObjects& theObjects )
559 MapOfUnordered aMapOfUnordered;
561 for ( int i = 1, n = theObjects.Length(); i <= n; ++i )
563 const Handle(HYDROData_Entity)& anObject = theObjects.Value( i );
564 if ( anObject.IsNull() || !anObject->IsHas2dPrs() )
567 Standard_Integer anObjZLevel = -1;
568 if ( anObject->GetZLevel( anObjZLevel ) )
570 continue; // Skip objects that already have the z-level
574 QString anObjName = anObject->GetName();
575 if ( anObjName.isEmpty() )
578 aMapOfUnordered.insert( anObjName, anObject );
582 if ( aMapOfUnordered.isEmpty() )
583 return; // Nothing to show
585 Standard_Integer aTopId = 0;
587 HYDROData_SequenceOfObjects aModelOrder = GetObjectsLayerOrder( Standard_False );
588 if ( !aModelOrder.IsEmpty() )
590 const Handle(HYDROData_Entity)& anObject = aModelOrder.First();
591 anObject->GetZLevel( aTopId );
595 aTopId += aMapOfUnordered.size() - 1;
597 QStringList aSortedNames = aMapOfUnordered.keys();
598 qSort( aSortedNames.begin(), aSortedNames.end(), isObjectNameLessThan );
600 for ( int i = 0; i < aSortedNames.length(); ++i )
602 QString anObjName = aSortedNames.value( i );
604 const Handle(HYDROData_Entity)& anObject = aMapOfUnordered.value( anObjName );
605 anObject->SetZLevel( aTopId-- );
609 void HYDROData_Document::RemoveObjectsLayerOrder()
611 HYDROData_Iterator anIter( this );
612 for ( ; anIter.More(); anIter.Next() )
614 Handle(HYDROData_Entity) anObject = anIter.Current();
615 if ( anObject.IsNull() || !anObject->IsHas2dPrs() )
618 anObject->RemoveZLevel();
622 void HYDROData_Document::StartOperation()
627 void HYDROData_Document::CommitOperation(const TCollection_ExtendedString& theName)
629 if( !myDoc->CommitCommand() ) // it means that there were no modifications done
632 NewID(); // workaround: do something just to modify the document
633 myDoc->CommitCommand();
635 myTransactionsAfterSave++;
637 if( theName.Length() != 0 )
639 const TDF_DeltaList& aList = GetUndos();
640 if( !aList.IsEmpty() )
642 Handle(TDF_Delta) aDelta = aList.Last();
643 if( !aDelta.IsNull() )
644 aDelta->SetName( theName );
649 void HYDROData_Document::AbortOperation()
651 myDoc->AbortCommand();
654 bool HYDROData_Document::IsOperation()
656 return myDoc->HasOpenCommand() != 0;
659 bool HYDROData_Document::IsModified()
661 return myTransactionsAfterSave != 0;
664 bool HYDROData_Document::CanUndo()
666 return myDoc->GetAvailableUndos() > 0;
669 const TDF_DeltaList& HYDROData_Document::GetUndos()
671 return myDoc->GetUndos();
674 void HYDROData_Document::ClearUndos()
676 return myDoc->ClearUndos();
679 void HYDROData_Document::Undo()
682 myTransactionsAfterSave--;
685 bool HYDROData_Document::CanRedo()
687 return myDoc->GetAvailableRedos() > 0;
690 const TDF_DeltaList& HYDROData_Document::GetRedos()
692 return myDoc->GetRedos();
695 void HYDROData_Document::ClearRedos()
697 return myDoc->ClearRedos();
700 void HYDROData_Document::Redo()
703 myTransactionsAfterSave++;
706 Handle(HYDROData_Entity) HYDROData_Document::CreateObject( const ObjectKind theKind )
708 return HYDROData_Iterator::CreateObject( this, theKind );
711 Handle(HYDROData_Entity) HYDROData_Document::FindObjectByName(
712 const QString& theName,
713 const ObjectKind theObjectKind ) const
715 Handle(HYDROData_Entity) anObject;
716 if ( theName.isEmpty() )
719 QStringList aNamesList;
720 aNamesList << theName;
722 HYDROData_SequenceOfObjects aSeqOfObjs = FindObjectsByNames( aNamesList, theObjectKind );
723 if( aSeqOfObjs.IsEmpty() )
726 anObject = aSeqOfObjs.First();
730 HYDROData_SequenceOfObjects HYDROData_Document::FindObjectsByNames(
731 const QStringList& theNames,
732 const ObjectKind theObjectKind ) const
734 HYDROData_SequenceOfObjects aResSeq;
736 QStringList aNamesList = theNames;
738 HYDROData_Iterator anIter( this, theObjectKind );
739 for( ; anIter.More(); anIter.Next() )
741 Handle(HYDROData_Entity) anObject = anIter.Current();
742 if( anObject.IsNull() )
745 QString anObjName = anObject->GetName();
746 if ( anObjName.isEmpty() || !aNamesList.contains( anObjName ) )
749 aResSeq.Append( anObject );
751 aNamesList.removeAll( anObjName );
752 if ( aNamesList.isEmpty() )
759 HYDROData_SequenceOfObjects HYDROData_Document::CollectAllObjects( const ObjectKind theObjectKind ) const
761 HYDROData_SequenceOfObjects aResSeq;
762 HYDROData_Iterator anIter( this, theObjectKind );
763 for( ; anIter.More(); anIter.Next() )
765 Handle(HYDROData_Entity) anObject = anIter.Current();
766 if( anObject.IsNull() )
768 aResSeq.Append( anObject );
773 HYDROData_Document::HYDROData_Document()
775 HYDROData_Application::GetApplication()->NewDocument("BinOcaf", myDoc);
776 myDoc->SetUndoLimit(UNDO_LIMIT);
777 NewID(); // needed to have at least one attribute in initial document to avoid errors
778 myTransactionsAfterSave = 0;
782 myInterpolatorsFactory = 0;
785 HYDROData_Document::HYDROData_Document(const Handle(TDocStd_Document)& theDoc)
788 myTransactionsAfterSave = 0;
792 myInterpolatorsFactory = 0;
795 HYDROData_Document::~HYDROData_Document()
799 int HYDROData_Document::NewID()
801 TDF_Label anIDLab = myDoc->Main().FindChild(TAG_PROPS).
802 FindChild(TAG_PROPS_NEW_ID);
803 Handle(TDataStd_Integer) anInt;
804 if (!anIDLab.FindAttribute(TDataStd_Integer::GetID(), anInt)) {
805 anInt = TDataStd_Integer::Set(anIDLab, 0);
806 anInt->SetID(TDataStd_Integer::GetID());
808 // just increment value and return
809 anInt->Set(anInt->Get() + 1);
813 TDF_Label HYDROData_Document::LabelOfObjects()
815 return myDoc->Main().FindChild(TAG_OBJECTS);
818 TDF_Label HYDROData_Document::LabelOfLocalCS() const
820 return myDoc->Main().FindChild(TAG_LOCAL_CS);
823 void HYDROData_Document::GetLocalCS( double& theLX, double& theLY ) const
825 TDF_Label aLocalCSLab = LabelOfLocalCS();
827 Handle( TDataXtd_Position ) aLocalCS;
828 if( aLocalCSLab.FindAttribute( TDataXtd_Position::GetID(), aLocalCS ) )
830 gp_Pnt aLocalCS3d = aLocalCS->GetPosition();
831 theLX = aLocalCS3d.X();
832 theLY = aLocalCS3d.Y();
836 theLX = DEFAULT_LOCAL_CS.X();
837 theLY = DEFAULT_LOCAL_CS.Y();
841 void HYDROData_Document::SetLocalCS( double theLX, double theLY )
845 // update the local CS data in attribute
846 TDF_Label aLocalCSLab = LabelOfLocalCS();
847 Handle( TDataXtd_Position ) aLocalCS;
848 if( !aLocalCSLab.FindAttribute( TDataXtd_Position::GetID(), aLocalCS ) )
850 aLocalCS = TDataXtd_Position::Set( aLocalCSLab );
851 aLocalCS->SetID(TDataXtd_Position::GetID());
854 gp_Pnt aLocalCS3d( theLX, theLY, 0 );
855 aLocalCS->SetPosition( aLocalCS3d );
857 // calculate delta for coordinates
858 double aDX = myLX - theLX;
859 double aDY = myLY - theLY;
861 // update the local CS data in internal fields
865 //update all objects in the document
866 HYDROData_Iterator anIterator( this, KIND_UNKNOWN );
867 for( ; anIterator.More(); anIterator.Next() )
868 anIterator.Current()->UpdateLocalCS( aDX, aDY );
871 void HYDROData_Document::UpdateLCSFields() const
873 if( myLX >= 0 && myLY >= 0 )
877 GetLocalCS( aLX, aLY );
878 HYDROData_Document* aThat = const_cast<HYDROData_Document*>( this );
883 void HYDROData_Document::Transform( double& X, double& Y, bool IsToLocalCS ) const
898 void HYDROData_Document::Transform( gp_Pnt& thePnt, bool IsToLocalCS ) const
900 double X = thePnt.X();
901 double Y = thePnt.Y();
902 double Z = thePnt.Z();
903 Transform( X, Y, IsToLocalCS );
904 thePnt = gp_Pnt( X, Y, Z );
907 void HYDROData_Document::Transform( gp_XYZ& thePnt, bool IsToLocalCS ) const
909 double X = thePnt.X();
910 double Y = thePnt.Y();
911 double Z = thePnt.Z();
912 Transform( X, Y, IsToLocalCS );
913 thePnt = gp_XYZ( X, Y, Z );
916 void HYDROData_Document::Transform( double& X, double& Y, double& Z, bool IsToLocalCS ) const
918 Transform( X, Y, IsToLocalCS );
921 void HYDROData_Document::Transform( gp_XY& thePnt, bool IsToLocalCS ) const
923 double X = thePnt.X();
924 double Y = thePnt.Y();
925 Transform( X, Y, IsToLocalCS );
926 thePnt = gp_XY( X, Y );
929 HYDROData_InterpolatorsFactory* HYDROData_Document::GetInterpolatorsFactory()
931 if ( !myInterpolatorsFactory ) {
932 myInterpolatorsFactory = new HYDROData_InterpolatorsFactory();
935 return myInterpolatorsFactory;
938 HYDROData_IProfilesInterpolator* HYDROData_Document::GetInterpolator( const TCollection_AsciiString& theName ) const
940 HYDROData_IProfilesInterpolator* anInterpolator = NULL;
942 HYDROData_Document* aThat = const_cast<HYDROData_Document*>( this );
943 HYDROData_InterpolatorsFactory* aFactory = aThat->GetInterpolatorsFactory();
945 anInterpolator = aFactory->GetInterpolator( theName );
948 return anInterpolator;
951 NCollection_Sequence<TCollection_AsciiString> HYDROData_Document::GetInterpolatorNames() const
953 NCollection_Sequence<TCollection_AsciiString> aNames;
955 HYDROData_Document* aThat = const_cast<HYDROData_Document*>( this );
956 HYDROData_InterpolatorsFactory* aFactory = aThat->GetInterpolatorsFactory();
958 aNames = aFactory->GetInterpolatorNames();
964 QColor HYDROData_Document::GetAssociatedColor( const QString& theStricklerType, const Handle(HYDROData_StricklerTable)& theTable ) const
966 if( !theTable.IsNull() && theTable->HasType( theStricklerType ) )
967 return theTable->GetColor( theStricklerType );
969 HYDROData_Iterator anIt( this, KIND_STRICKLER_TABLE );
970 for( ; anIt.More(); anIt.Next() )
972 Handle(HYDROData_StricklerTable) aTable = Handle(HYDROData_StricklerTable)::DownCast( anIt.Current() );
973 if( aTable->HasType( theStricklerType ) )
974 return aTable->GetColor( theStricklerType );
979 void HYDROData_Document::CollectQGISValues( const QString& theAttrName,
980 QStringList& theAttrValues,
981 QStringList& theStricklerTypes ) const
983 HYDROData_Iterator It( this, KIND_STRICKLER_TABLE );
984 for( ; It.More(); It.Next() )
986 Handle(HYDROData_StricklerTable) aTable = Handle(HYDROData_StricklerTable)::DownCast( It.Current() );
987 if( !aTable.IsNull() && aTable->GetAttrName()==theAttrName )
989 theAttrValues.clear();
990 theStricklerTypes = aTable->GetTypes();
991 foreach( QString aType, theStricklerTypes )
993 QString anAttrValue = aTable->GetAttrValue( aType );
994 theAttrValues.append( anAttrValue );