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()
63 Handle(HYDROData_Document) aResult =
64 HYDROData_Application::GetApplication()->GetDocument();
65 if (aResult.IsNull()) {
66 aResult = new HYDROData_Document();
67 HYDROData_Application::GetApplication()->AddDocument(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();
92 aResDoc = anApp->GetDocument();
97 bool HYDROData_Document::HasDocument()
99 Handle(HYDROData_Document) aResult =
100 HYDROData_Application::GetApplication()->GetDocument();
101 return !aResult.IsNull();
104 Data_DocError HYDROData_Document::Load(const char* theFileName)
106 Handle(TDocStd_Document) aResult;
107 TCollection_ExtendedString aPath ((const Standard_CString)theFileName);
108 PCDM_ReaderStatus aStatus = (PCDM_ReaderStatus) -1;
111 aStatus = HYDROData_Application::GetApplication()->Open (aPath, aResult);
113 catch (Standard_Failure)
115 if (!aResult.IsNull()) {
116 aResult->SetUndoLimit(UNDO_LIMIT);
117 HYDROData_Application::GetApplication()->AddDocument(new HYDROData_Document(aResult));
120 Data_DocError anError;
123 anError = DocError_OK;
125 case PCDM_RS_NoDriver:
126 case PCDM_RS_UnknownFileDriver:
127 case PCDM_RS_NoSchema:
128 case PCDM_RS_DriverFailure:
129 case PCDM_RS_WrongResource:
130 anError = DocError_ResourcesProblem;
132 case PCDM_RS_OpenError:
133 case PCDM_RS_NoDocument:
134 case PCDM_RS_WrongStreamMode:
135 case PCDM_RS_PermissionDenied:
136 anError = DocError_CanNotOpen;
138 case PCDM_RS_NoVersion:
139 anError = DocError_InvalidVersion;
141 case PCDM_RS_ExtensionFailure:
142 case PCDM_RS_FormatFailure:
143 case PCDM_RS_TypeFailure:
144 case PCDM_RS_TypeNotFoundInSchema:
145 case PCDM_RS_UnrecognizedFileFormat:
146 anError = DocError_InvalidFormat;
148 case PCDM_RS_MakeFailure:
150 anError = DocError_UnknownProblem;
156 Data_DocError HYDROData_Document::Save(const char* theFileName)
158 TCollection_ExtendedString aPath ((const Standard_CString)theFileName);
159 PCDM_StoreStatus aStatus;
161 aStatus = HYDROData_Application::GetApplication()->SaveAs (myDoc, aPath);
163 catch (Standard_Failure) {}
164 myTransactionsAfterSave = 0;
165 Standard::Purge(); // Release free memory
168 Data_DocError anError;
171 anError = DocError_OK;
173 case PCDM_SS_DriverFailure:
174 anError = DocError_ResourcesProblem;
176 case PCDM_SS_WriteFailure:
177 //case PCDM_SS_DiskWritingFailure:
178 //case PCDM_SS_UserRightsFailure:
179 anError = DocError_CanNotOpen;
182 anError = DocError_UnknownProblem;
188 void HYDROData_Document::Close()
191 HYDROData_Application::GetApplication()->RemoveDocument(this);
194 double HYDROData_Document::GetDefaultStricklerCoefficient() const
197 TDF_Label aLabel = myDoc->Main().FindChild(TAG_DEF_STRICKLER_COEFF, Standard_False);
198 if ( !aLabel.IsNull() )
200 Handle(TDataStd_Real) anAttr;
201 if ( aLabel.FindAttribute( TDataStd_Real::GetID(), anAttr ) )
202 aRes = anAttr->Get();
208 void HYDROData_Document::SetDefaultStricklerCoefficient( double theCoeff ) const
210 TDF_Label aLabel = myDoc->Main().FindChild(TAG_DEF_STRICKLER_COEFF);
211 if ( !aLabel.IsNull() )
213 Handle(TDataStd_Real) anAttr;
214 if ( !aLabel.FindAttribute( TDataStd_Real::GetID(), anAttr ) )
216 anAttr = new TDataStd_Real();
217 aLabel.AddAttribute(anAttr);
218 anAttr->SetID(TDataStd_Real::GetID());
220 anAttr->Set( theCoeff );
224 int HYDROData_Document::GetCountQuadtree() const
227 TDF_Label aLabel = myDoc->Main().FindChild(TAG_COUNT_QUADTREE, Standard_False);
228 if ( !aLabel.IsNull() )
230 Handle(TDataStd_Integer) anAttr;
231 if ( aLabel.FindAttribute( TDataStd_Integer::GetID(), anAttr ) )
232 nbQuad = anAttr->Get();
237 void HYDROData_Document::SetCountQuadtree( int nbQuad) const
239 TDF_Label aLabel = myDoc->Main().FindChild(TAG_COUNT_QUADTREE);
240 if ( !aLabel.IsNull() )
242 Handle(TDataStd_Integer) anAttr;
243 if ( !aLabel.FindAttribute( TDataStd_Integer::GetID(), anAttr ) )
245 anAttr = new TDataStd_Integer();
246 aLabel.AddAttribute(anAttr);
247 anAttr->SetID(TDataStd_Integer::GetID());
249 anAttr->Set( nbQuad );
253 int HYDROData_Document::GetCountDelaunay() const
256 TDF_Label aLabel = myDoc->Main().FindChild(TAG_COUNT_DELAUNAY, Standard_False);
257 if ( !aLabel.IsNull() )
259 Handle(TDataStd_Integer) anAttr;
260 if ( aLabel.FindAttribute( TDataStd_Integer::GetID(), anAttr ) )
261 nbDelaunay = anAttr->Get();
266 void HYDROData_Document::SetCountDelaunay( int nbDelaunay) const
268 TDF_Label aLabel = myDoc->Main().FindChild(TAG_COUNT_DELAUNAY);
269 if ( !aLabel.IsNull() )
271 Handle(TDataStd_Integer) anAttr;
272 if ( !aLabel.FindAttribute( TDataStd_Integer::GetID(), anAttr ) )
274 anAttr = new TDataStd_Integer();
275 aLabel.AddAttribute(anAttr);
276 anAttr->SetID(TDataStd_Integer::GetID());
278 anAttr->Set( nbDelaunay );
282 bool HYDROData_Document::DumpToPython( const QString& thePyScriptPath,
283 const bool theIsMultiFile ) const
285 // Try to open the file
286 QFile aFile( thePyScriptPath );
287 if ( !aFile.open( QIODevice::WriteOnly | QFile::Text ) )
290 MapOfTreatedObjects aTreatedObjects;
292 // Dump header for python script
293 QStringList aHeaderDump = DumpToPython( thePyScriptPath, aTreatedObjects, theIsMultiFile );
294 if ( aHeaderDump.isEmpty() )
297 HYDROData_Tool::WriteStringsToFile( aFile, aHeaderDump );
301 // Dump the local CS data to Python
303 QString aLCS = QString( "%1.SetLocalCS( %2, %3 )" ).arg( GetDocPyName() ).arg( myLX, 0, 'f', 3 ).arg( myLY, 0, 'f', 3 );
306 HYDROData_Tool::WriteStringsToFile( aFile, QStringList() << aLCS );
308 // Dump all model objects to Python script
309 aRes = aRes && dumpPartitionToPython( aFile, thePyScriptPath, theIsMultiFile, aTreatedObjects, KIND_IMAGE );
310 aRes = aRes && dumpPartitionToPython( aFile, thePyScriptPath, theIsMultiFile, aTreatedObjects, KIND_STRICKLER_TABLE );
311 aRes = aRes && dumpPartitionToPython( aFile, thePyScriptPath, theIsMultiFile, aTreatedObjects, KIND_POLYLINEXY );
312 aRes = aRes && dumpPartitionToPython( aFile, thePyScriptPath, theIsMultiFile, aTreatedObjects, KIND_BATHYMETRY );
313 aRes = aRes && dumpPartitionToPython( aFile, thePyScriptPath, theIsMultiFile, aTreatedObjects, KIND_PROFILE );
314 aRes = aRes && dumpPartitionToPython( aFile, thePyScriptPath, theIsMultiFile, aTreatedObjects, KIND_POLYLINE );
315 aRes = aRes && dumpPartitionToPython( aFile, thePyScriptPath, theIsMultiFile, aTreatedObjects, KIND_IMMERSIBLE_ZONE );
316 aRes = aRes && dumpPartitionToPython( aFile, thePyScriptPath, theIsMultiFile, aTreatedObjects, KIND_STREAM );
317 aRes = aRes && dumpPartitionToPython( aFile, thePyScriptPath, theIsMultiFile, aTreatedObjects, KIND_CHANNEL );
318 aRes = aRes && dumpPartitionToPython( aFile, thePyScriptPath, theIsMultiFile, aTreatedObjects, KIND_DIGUE );
319 aRes = aRes && dumpPartitionToPython( aFile, thePyScriptPath, theIsMultiFile, aTreatedObjects, KIND_OBSTACLE );
320 aRes = aRes && dumpPartitionToPython( aFile, thePyScriptPath, theIsMultiFile, aTreatedObjects, KIND_LAND_COVER_MAP );
321 aRes = aRes && dumpPartitionToPython( aFile, thePyScriptPath, theIsMultiFile, aTreatedObjects, KIND_BC_POLYGON );
322 aRes = aRes && dumpPartitionToPython( aFile, thePyScriptPath, theIsMultiFile, aTreatedObjects, KIND_CALCULATION );
324 // Dump code to close python fuction
325 if ( aRes && theIsMultiFile )
327 QStringList aFooterScript;
328 aFooterScript << QString( "" );
329 aFooterScript << QString( " pass" );
330 HYDROData_Tool::WriteStringsToFile( aFile, aFooterScript );
336 QString HYDROData_Document::GetDocPyName() const
338 QString aDocName = PYTHON_DOC_NAME;
343 QStringList HYDROData_Document::DumpToPython( const QString& thePyScriptPath,
344 MapOfTreatedObjects& theTreatedObjects,
345 const bool theIsMultiFile ) const
347 QString aDocName = GetDocPyName();
349 // Append document in to the map of treated objects to prevent names overlaping
350 theTreatedObjects.insert( aDocName, this );
352 QStringList aResScript;
354 aResScript << QString( "from HYDROPy import *" );
355 aResScript << QString( "from PyQt5.QtCore import *" );
356 aResScript << QString( "from PyQt5.QtGui import *" );
358 if ( theIsMultiFile )
360 aResScript << QString( "import salome" );
361 aResScript << QString( "" );
362 aResScript << QString( "def RebuildData():" );
363 aResScript << QString( " %1 = HYDROData_Document.Document()" ).arg( aDocName );
367 aResScript << QString( "" );
368 aResScript << QString( "%1 = HYDROData_Document.Document()" ).arg( aDocName );
374 bool HYDROData_Document::dumpPartitionToPython( QFile& theFile,
375 const QString& thePyScriptPath,
376 const bool theIsMultiFile,
377 MapOfTreatedObjects& theTreatedObjects,
378 const ObjectKind& theObjectKind ) const
380 if ( !theFile.isOpen() )
383 QTextStream anOutStream( &theFile );
387 HYDROData_Iterator anIterator( this, theObjectKind );
388 for( ; anIterator.More(); anIterator.Next() )
390 Handle(HYDROData_Entity) anObject = anIterator.Current();
391 if ( anObject.IsNull() )
394 QString anObjName = anObject->GetName();
395 if ( theTreatedObjects.contains( anObjName ) )
398 theTreatedObjects.insert( anObjName, anObject );
400 QStringList anObjDump = anObject->DumpToPython( thePyScriptPath, theTreatedObjects );
402 if ( theIsMultiFile )
404 // For multifile dump we use the function, see the document dump header
405 QStringList::iterator anIt = anObjDump.begin();
406 for ( ; anIt != anObjDump.end(); ++anIt )
407 anIt->prepend( " " );
410 HYDROData_Tool::WriteStringsToFile( theFile, anObjDump );
416 bool takeLastDigits( QString& theStr, int& aRes )
421 for ( int i = theStr.length() - 1; i >= 0; --i )
423 const QChar& aChar = theStr.at( i );
424 if ( !aChar.isDigit() )
427 anStrNum.prepend( aChar );
430 if ( anStrNum.isEmpty() )
433 theStr.remove( theStr.length() - anStrNum.length(), anStrNum.length() );
434 aRes = anStrNum.toInt();
439 bool isObjectNameLessThan( const QString& theStr1, const QString& theStr2 )
441 QString aStr1 = theStr1, aStr2 = theStr2;
443 int aNum1 = -1, aNum2 = -1;
444 if ( takeLastDigits( aStr1, aNum1 ) && takeLastDigits( aStr2, aNum2 ) )
446 if ( aStr1 == aStr2 )
447 return aNum1 < aNum2;
450 return theStr1 < theStr2;
453 HYDROData_SequenceOfObjects HYDROData_Document::GetObjectsLayerOrder(
454 const Standard_Boolean theIsAll ) const
456 HYDROData_SequenceOfObjects anOrder;
458 MapOfOrdered aMapOfOrdered;
459 MapOfUnordered aMapOfUnordered;
461 HYDROData_Iterator anIter( this );
462 for ( ; anIter.More(); anIter.Next() )
464 Handle(HYDROData_Entity) anObject = anIter.Current();
465 if ( anObject.IsNull() || !anObject->IsHas2dPrs() )
468 Standard_Integer anObjZLevel = -1;
469 if ( anObject->GetZLevel( anObjZLevel ) )
471 aMapOfOrdered.insert( anObjZLevel, anObject );
475 QString anObjName = anObject->GetName();
476 if ( anObjName.isEmpty() )
479 aMapOfUnordered.insert( anObjName, anObject );
483 MapOfOrdered::const_iterator anOrderedMapIt = aMapOfOrdered.constBegin();
484 for ( ; anOrderedMapIt != aMapOfOrdered.constEnd(); anOrderedMapIt++ )
486 const Handle(HYDROData_Entity)& anObject = anOrderedMapIt.value();
487 anOrder.Prepend( anObject );
492 QStringList aSortedNames = aMapOfUnordered.keys();
493 qSort( aSortedNames.begin(), aSortedNames.end(), isObjectNameLessThan );
495 for ( int i = 0; i < aSortedNames.length(); ++i )
497 QString anObjName = aSortedNames.value( i );
499 const Handle(HYDROData_Entity)& anObject = aMapOfUnordered.value( anObjName );
500 anOrder.Append( anObject );
507 void HYDROData_Document::SetObjectsLayerOrder( const HYDROData_SequenceOfObjects& theOrder )
509 // At first we remove previous model order
510 RemoveObjectsLayerOrder();
512 // Make new objects order
513 Standard_Integer aLevel = 0;
514 for ( int i = theOrder.Length(), n = 1; i >= n; --i )
516 const Handle(HYDROData_Entity)& anObject = theOrder.Value( i );
517 if ( anObject.IsNull() || !anObject->IsHas2dPrs() )
520 anObject->SetZLevel( aLevel++ );
524 void HYDROData_Document::Show( const Handle(HYDROData_Entity)& theObject )
526 HYDROData_SequenceOfObjects anOrder;
527 anOrder.Append( theObject );
531 void HYDROData_Document::Show( const HYDROData_SequenceOfObjects& theObjects )
533 MapOfUnordered aMapOfUnordered;
535 for ( int i = 1, n = theObjects.Length(); i <= n; ++i )
537 const Handle(HYDROData_Entity)& anObject = theObjects.Value( i );
538 if ( anObject.IsNull() || !anObject->IsHas2dPrs() )
541 Standard_Integer anObjZLevel = -1;
542 if ( anObject->GetZLevel( anObjZLevel ) )
544 continue; // Skip objects that already have the z-level
548 QString anObjName = anObject->GetName();
549 if ( anObjName.isEmpty() )
552 aMapOfUnordered.insert( anObjName, anObject );
556 if ( aMapOfUnordered.isEmpty() )
557 return; // Nothing to show
559 Standard_Integer aTopId = 0;
561 HYDROData_SequenceOfObjects aModelOrder = GetObjectsLayerOrder( Standard_False );
562 if ( !aModelOrder.IsEmpty() )
564 const Handle(HYDROData_Entity)& anObject = aModelOrder.First();
565 anObject->GetZLevel( aTopId );
569 aTopId += aMapOfUnordered.size() - 1;
571 QStringList aSortedNames = aMapOfUnordered.keys();
572 qSort( aSortedNames.begin(), aSortedNames.end(), isObjectNameLessThan );
574 for ( int i = 0; i < aSortedNames.length(); ++i )
576 QString anObjName = aSortedNames.value( i );
578 const Handle(HYDROData_Entity)& anObject = aMapOfUnordered.value( anObjName );
579 anObject->SetZLevel( aTopId-- );
583 void HYDROData_Document::RemoveObjectsLayerOrder()
585 HYDROData_Iterator anIter( this );
586 for ( ; anIter.More(); anIter.Next() )
588 Handle(HYDROData_Entity) anObject = anIter.Current();
589 if ( anObject.IsNull() || !anObject->IsHas2dPrs() )
592 anObject->RemoveZLevel();
596 void HYDROData_Document::StartOperation()
601 void HYDROData_Document::CommitOperation(const TCollection_ExtendedString& theName)
603 if( !myDoc->CommitCommand() ) // it means that there were no modifications done
606 NewID(); // workaround: do something just to modify the document
607 myDoc->CommitCommand();
609 myTransactionsAfterSave++;
611 if( theName.Length() != 0 )
613 const TDF_DeltaList& aList = GetUndos();
614 if( !aList.IsEmpty() )
616 Handle(TDF_Delta) aDelta = aList.Last();
617 if( !aDelta.IsNull() )
618 aDelta->SetName( theName );
623 void HYDROData_Document::AbortOperation()
625 myDoc->AbortCommand();
628 bool HYDROData_Document::IsOperation()
630 return myDoc->HasOpenCommand() != 0;
633 bool HYDROData_Document::IsModified()
635 return myTransactionsAfterSave != 0;
638 bool HYDROData_Document::CanUndo()
640 return myDoc->GetAvailableUndos() > 0;
643 const TDF_DeltaList& HYDROData_Document::GetUndos()
645 return myDoc->GetUndos();
648 void HYDROData_Document::ClearUndos()
650 return myDoc->ClearUndos();
653 void HYDROData_Document::Undo()
656 myTransactionsAfterSave--;
659 bool HYDROData_Document::CanRedo()
661 return myDoc->GetAvailableRedos() > 0;
664 const TDF_DeltaList& HYDROData_Document::GetRedos()
666 return myDoc->GetRedos();
669 void HYDROData_Document::ClearRedos()
671 return myDoc->ClearRedos();
674 void HYDROData_Document::Redo()
677 myTransactionsAfterSave++;
680 Handle(HYDROData_Entity) HYDROData_Document::CreateObject( const ObjectKind theKind )
682 return HYDROData_Iterator::CreateObject( this, theKind );
685 Handle(HYDROData_Entity) HYDROData_Document::FindObjectByName(
686 const QString& theName,
687 const ObjectKind theObjectKind ) const
689 Handle(HYDROData_Entity) anObject;
690 if ( theName.isEmpty() )
693 QStringList aNamesList;
694 aNamesList << theName;
696 HYDROData_SequenceOfObjects aSeqOfObjs = FindObjectsByNames( aNamesList, theObjectKind );
697 if( aSeqOfObjs.IsEmpty() )
700 anObject = aSeqOfObjs.First();
704 HYDROData_SequenceOfObjects HYDROData_Document::FindObjectsByNames(
705 const QStringList& theNames,
706 const ObjectKind theObjectKind ) const
708 HYDROData_SequenceOfObjects aResSeq;
710 QStringList aNamesList = theNames;
712 HYDROData_Iterator anIter( this, theObjectKind );
713 for( ; anIter.More(); anIter.Next() )
715 Handle(HYDROData_Entity) anObject = anIter.Current();
716 if( anObject.IsNull() )
719 QString anObjName = anObject->GetName();
720 if ( anObjName.isEmpty() || !aNamesList.contains( anObjName ) )
723 aResSeq.Append( anObject );
725 aNamesList.removeAll( anObjName );
726 if ( aNamesList.isEmpty() )
733 HYDROData_SequenceOfObjects HYDROData_Document::CollectAllObjects( const ObjectKind theObjectKind ) const
735 HYDROData_SequenceOfObjects aResSeq;
736 HYDROData_Iterator anIter( this, theObjectKind );
737 for( ; anIter.More(); anIter.Next() )
739 Handle(HYDROData_Entity) anObject = anIter.Current();
740 if( anObject.IsNull() )
742 aResSeq.Append( anObject );
747 HYDROData_Document::HYDROData_Document()
749 HYDROData_Application::GetApplication()->NewDocument("BinOcaf", myDoc);
750 myDoc->SetUndoLimit(UNDO_LIMIT);
751 NewID(); // needed to have at least one attribute in initial document to avoid errors
752 myTransactionsAfterSave = 0;
756 myInterpolatorsFactory = 0;
759 HYDROData_Document::HYDROData_Document(const Handle(TDocStd_Document)& theDoc)
762 myTransactionsAfterSave = 0;
766 myInterpolatorsFactory = 0;
769 HYDROData_Document::~HYDROData_Document()
773 int HYDROData_Document::NewID()
775 TDF_Label anIDLab = myDoc->Main().FindChild(TAG_PROPS).
776 FindChild(TAG_PROPS_NEW_ID);
777 Handle(TDataStd_Integer) anInt;
778 if (!anIDLab.FindAttribute(TDataStd_Integer::GetID(), anInt)) {
779 anInt = TDataStd_Integer::Set(anIDLab, 0);
780 anInt->SetID(TDataStd_Integer::GetID());
782 // just increment value and return
783 anInt->Set(anInt->Get() + 1);
787 TDF_Label HYDROData_Document::LabelOfObjects()
789 return myDoc->Main().FindChild(TAG_OBJECTS);
792 TDF_Label HYDROData_Document::LabelOfLocalCS() const
794 return myDoc->Main().FindChild(TAG_LOCAL_CS);
797 void HYDROData_Document::GetLocalCS( double& theLX, double& theLY ) const
799 TDF_Label aLocalCSLab = LabelOfLocalCS();
801 Handle( TDataXtd_Position ) aLocalCS;
802 if( aLocalCSLab.FindAttribute( TDataXtd_Position::GetID(), aLocalCS ) )
804 gp_Pnt aLocalCS3d = aLocalCS->GetPosition();
805 theLX = aLocalCS3d.X();
806 theLY = aLocalCS3d.Y();
810 theLX = DEFAULT_LOCAL_CS.X();
811 theLY = DEFAULT_LOCAL_CS.Y();
815 void HYDROData_Document::SetLocalCS( double theLX, double theLY )
819 // update the local CS data in attribute
820 TDF_Label aLocalCSLab = LabelOfLocalCS();
821 Handle( TDataXtd_Position ) aLocalCS;
822 if( !aLocalCSLab.FindAttribute( TDataXtd_Position::GetID(), aLocalCS ) )
824 aLocalCS = TDataXtd_Position::Set( aLocalCSLab );
825 aLocalCS->SetID(TDataXtd_Position::GetID());
828 gp_Pnt aLocalCS3d( theLX, theLY, 0 );
829 aLocalCS->SetPosition( aLocalCS3d );
831 // calculate delta for coordinates
832 double aDX = myLX - theLX;
833 double aDY = myLY - theLY;
835 // update the local CS data in internal fields
839 //update all objects in the document
840 HYDROData_Iterator anIterator( this, KIND_UNKNOWN );
841 for( ; anIterator.More(); anIterator.Next() )
842 anIterator.Current()->UpdateLocalCS( aDX, aDY );
845 void HYDROData_Document::UpdateLCSFields() const
847 if( myLX >= 0 && myLY >= 0 )
851 GetLocalCS( aLX, aLY );
852 HYDROData_Document* aThat = const_cast<HYDROData_Document*>( this );
857 void HYDROData_Document::Transform( double& X, double& Y, bool IsToLocalCS ) const
872 void HYDROData_Document::Transform( gp_Pnt& thePnt, bool IsToLocalCS ) const
874 double X = thePnt.X();
875 double Y = thePnt.Y();
876 double Z = thePnt.Z();
877 Transform( X, Y, IsToLocalCS );
878 thePnt = gp_Pnt( X, Y, Z );
881 void HYDROData_Document::Transform( gp_XYZ& thePnt, bool IsToLocalCS ) const
883 double X = thePnt.X();
884 double Y = thePnt.Y();
885 double Z = thePnt.Z();
886 Transform( X, Y, IsToLocalCS );
887 thePnt = gp_XYZ( X, Y, Z );
890 void HYDROData_Document::Transform( double& X, double& Y, double& Z, bool IsToLocalCS ) const
892 Transform( X, Y, IsToLocalCS );
895 void HYDROData_Document::Transform( gp_XY& thePnt, bool IsToLocalCS ) const
897 double X = thePnt.X();
898 double Y = thePnt.Y();
899 Transform( X, Y, IsToLocalCS );
900 thePnt = gp_XY( X, Y );
903 HYDROData_InterpolatorsFactory* HYDROData_Document::GetInterpolatorsFactory()
905 if ( !myInterpolatorsFactory ) {
906 myInterpolatorsFactory = new HYDROData_InterpolatorsFactory();
909 return myInterpolatorsFactory;
912 HYDROData_IProfilesInterpolator* HYDROData_Document::GetInterpolator( const TCollection_AsciiString& theName ) const
914 HYDROData_IProfilesInterpolator* anInterpolator = NULL;
916 HYDROData_Document* aThat = const_cast<HYDROData_Document*>( this );
917 HYDROData_InterpolatorsFactory* aFactory = aThat->GetInterpolatorsFactory();
919 anInterpolator = aFactory->GetInterpolator( theName );
922 return anInterpolator;
925 NCollection_Sequence<TCollection_AsciiString> HYDROData_Document::GetInterpolatorNames() const
927 NCollection_Sequence<TCollection_AsciiString> aNames;
929 HYDROData_Document* aThat = const_cast<HYDROData_Document*>( this );
930 HYDROData_InterpolatorsFactory* aFactory = aThat->GetInterpolatorsFactory();
932 aNames = aFactory->GetInterpolatorNames();
938 QColor HYDROData_Document::GetAssociatedColor( const QString& theStricklerType, const Handle(HYDROData_StricklerTable)& theTable ) const
940 if( !theTable.IsNull() && theTable->HasType( theStricklerType ) )
941 return theTable->GetColor( theStricklerType );
943 HYDROData_Iterator anIt( this, KIND_STRICKLER_TABLE );
944 for( ; anIt.More(); anIt.Next() )
946 Handle(HYDROData_StricklerTable) aTable = Handle(HYDROData_StricklerTable)::DownCast( anIt.Current() );
947 if( aTable->HasType( theStricklerType ) )
948 return aTable->GetColor( theStricklerType );
953 void HYDROData_Document::CollectQGISValues( const QString& theAttrName,
954 QStringList& theAttrValues,
955 QStringList& theStricklerTypes ) const
957 HYDROData_Iterator It( this, KIND_STRICKLER_TABLE );
958 for( ; It.More(); It.Next() )
960 Handle(HYDROData_StricklerTable) aTable = Handle(HYDROData_StricklerTable)::DownCast( It.Current() );
961 if( !aTable.IsNull() && aTable->GetAttrName()==theAttrName )
963 theAttrValues.clear();
964 theStricklerTypes = aTable->GetTypes();
965 foreach( QString aType, theStricklerTypes )
967 QString anAttrValue = aTable->GetAttrValue( aType );
968 theAttrValues.append( anAttrValue );