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_HANDLE(HYDROData_Document,MMgt_TShared)
41 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Document,MMgt_TShared)
43 #define PYTHON_DOC_NAME "hydro_doc"
45 static const int UNDO_LIMIT = 10; // number of possible undo operations in the module
47 static const int TAG_PROPS = 1; // general properties tag
48 static const int TAG_PROPS_NEW_ID = 1; // general properties: tag for storage of the new object ID
49 static const int TAG_OBJECTS = 2; // tag of the objects sub-tree
50 static const int TAG_HISTORY = 3; // tag of the history sub-tree (Root for History)
51 static const int TAG_LOCAL_CS = 4; // tag of local coordinate system information
52 static const int TAG_DEF_STRICKLER_COEFF = 5; // tag of default strickler coefficient
53 static const gp_Pnt2d DEFAULT_LOCAL_CS( 0, 0 );
57 typedef QMap<Standard_Integer,Handle_HYDROData_Entity> MapOfOrdered;
58 typedef QMap<QString,Handle_HYDROData_Entity> MapOfUnordered;
60 Handle(HYDROData_Document) HYDROData_Document::Document(const int theStudyID)
62 Handle(HYDROData_Document) aResult =
63 HYDROData_Application::GetApplication()->GetDocument(theStudyID);
64 if (aResult.IsNull()) {
65 aResult = new HYDROData_Document();
66 HYDROData_Application::GetApplication()->AddDocument(theStudyID, aResult);
71 Handle(HYDROData_Document) HYDROData_Document::Document(
72 const TDF_Label& theObjectLabel )
74 Handle(HYDROData_Document) aResDoc;
75 if ( theObjectLabel.IsNull() )
78 Handle(TDocStd_Document) anObjDoc;
81 anObjDoc = TDocStd_Document::Get( theObjectLabel );
87 if ( anObjDoc.IsNull() )
90 HYDROData_Application* anApp = HYDROData_Application::GetApplication();
92 DataMapOfStudyIDDocument::Iterator aMapIt( anApp->myDocuments );
93 for ( ; aMapIt.More(); aMapIt.Next() )
95 Handle(HYDROData_Document) anAppDoc = aMapIt.Value();
96 if ( anAppDoc.IsNull() || anAppDoc->myDoc != anObjDoc )
106 bool HYDROData_Document::HasDocument(const int theStudyID)
108 Handle(HYDROData_Document) aResult =
109 HYDROData_Application::GetApplication()->GetDocument(theStudyID);
110 return !aResult.IsNull();
113 bool HYDROData_Document::DocumentId(const Handle(HYDROData_Document)& theDocument,
116 return HYDROData_Application::GetApplication()->GetDocumentId(theDocument, theDocId);
119 Data_DocError HYDROData_Document::Load(const char* theFileName, const int theStudyID)
121 Handle(TDocStd_Document) aResult;
122 TCollection_ExtendedString aPath ((const Standard_CString)theFileName);
123 PCDM_ReaderStatus aStatus = (PCDM_ReaderStatus) -1;
126 aStatus = HYDROData_Application::GetApplication()->Open (aPath, aResult);
128 catch (Standard_Failure)
130 if (!aResult.IsNull()) {
131 aResult->SetUndoLimit(UNDO_LIMIT);
132 HYDROData_Application::GetApplication()->AddDocument(theStudyID, new HYDROData_Document(aResult));
135 Data_DocError anError;
138 anError = DocError_OK;
140 case PCDM_RS_NoDriver:
141 case PCDM_RS_UnknownFileDriver:
142 case PCDM_RS_NoSchema:
143 case PCDM_RS_DriverFailure:
144 case PCDM_RS_WrongResource:
145 anError = DocError_ResourcesProblem;
147 case PCDM_RS_OpenError:
148 case PCDM_RS_NoDocument:
149 case PCDM_RS_WrongStreamMode:
150 case PCDM_RS_PermissionDenied:
151 anError = DocError_CanNotOpen;
153 case PCDM_RS_NoVersion:
154 anError = DocError_InvalidVersion;
156 case PCDM_RS_ExtensionFailure:
157 case PCDM_RS_FormatFailure:
158 case PCDM_RS_TypeFailure:
159 case PCDM_RS_TypeNotFoundInSchema:
160 case PCDM_RS_UnrecognizedFileFormat:
161 anError = DocError_InvalidFormat;
163 case PCDM_RS_MakeFailure:
165 anError = DocError_UnknownProblem;
171 Data_DocError HYDROData_Document::Save(const char* theFileName)
173 TCollection_ExtendedString aPath ((const Standard_CString)theFileName);
174 PCDM_StoreStatus aStatus;
176 aStatus = HYDROData_Application::GetApplication()->SaveAs (myDoc, aPath);
178 catch (Standard_Failure) {}
179 myTransactionsAfterSave = 0;
180 Standard::Purge(); // Release free memory
183 Data_DocError anError;
186 anError = DocError_OK;
188 case PCDM_SS_DriverFailure:
189 anError = DocError_ResourcesProblem;
191 case PCDM_SS_WriteFailure:
192 //case PCDM_SS_DiskWritingFailure:
193 //case PCDM_SS_UserRightsFailure:
194 anError = DocError_CanNotOpen;
197 anError = DocError_UnknownProblem;
203 void HYDROData_Document::Close()
206 HYDROData_Application::GetApplication()->RemoveDocument(this);
209 double HYDROData_Document::GetDefaultStricklerCoefficient() const
212 TDF_Label aLabel = myDoc->Main().FindChild(TAG_DEF_STRICKLER_COEFF, Standard_False);
213 if ( !aLabel.IsNull() )
215 Handle(TDataStd_Real) anAttr;
216 if ( aLabel.FindAttribute( TDataStd_Real::GetID(), anAttr ) )
217 aRes = anAttr->Get();
223 void HYDROData_Document::SetDefaultStricklerCoefficient( double theCoeff ) const
225 TDF_Label aLabel = myDoc->Main().FindChild(TAG_DEF_STRICKLER_COEFF);
226 if ( !aLabel.IsNull() )
228 Handle(TDataStd_Real) anAttr;
229 if ( !aLabel.FindAttribute( TDataStd_Real::GetID(), anAttr ) )
230 aLabel.AddAttribute( anAttr = new TDataStd_Real() );
231 anAttr->Set( theCoeff );
235 bool HYDROData_Document::DumpToPython( const QString& thePyScriptPath,
236 const bool theIsMultiFile ) const
238 // Try to open the file
239 QFile aFile( thePyScriptPath );
240 if ( !aFile.open( QIODevice::WriteOnly | QFile::Text ) )
243 MapOfTreatedObjects aTreatedObjects;
245 // Dump header for python script
246 QStringList aHeaderDump = DumpToPython( thePyScriptPath, aTreatedObjects, theIsMultiFile );
247 if ( aHeaderDump.isEmpty() )
250 HYDROData_Tool::WriteStringsToFile( aFile, aHeaderDump );
254 // Dump the local CS data to Python
256 QString aLCS = QString( "%1.SetLocalCS( %2, %3 )" ).arg( GetDocPyName() ).arg( myLX, 0, 'f', 3 ).arg( myLY, 0, 'f', 3 );
259 HYDROData_Tool::WriteStringsToFile( aFile, QStringList() << aLCS );
261 // Dump all model objects to Python script
262 aRes = aRes && dumpPartitionToPython( aFile, thePyScriptPath, theIsMultiFile, aTreatedObjects, KIND_IMAGE );
263 aRes = aRes && dumpPartitionToPython( aFile, thePyScriptPath, theIsMultiFile, aTreatedObjects, KIND_STRICKLER_TABLE );
264 aRes = aRes && dumpPartitionToPython( aFile, thePyScriptPath, theIsMultiFile, aTreatedObjects, KIND_POLYLINEXY );
265 aRes = aRes && dumpPartitionToPython( aFile, thePyScriptPath, theIsMultiFile, aTreatedObjects, KIND_BATHYMETRY );
266 aRes = aRes && dumpPartitionToPython( aFile, thePyScriptPath, theIsMultiFile, aTreatedObjects, KIND_PROFILE );
267 aRes = aRes && dumpPartitionToPython( aFile, thePyScriptPath, theIsMultiFile, aTreatedObjects, KIND_POLYLINE );
268 aRes = aRes && dumpPartitionToPython( aFile, thePyScriptPath, theIsMultiFile, aTreatedObjects, KIND_IMMERSIBLE_ZONE );
269 aRes = aRes && dumpPartitionToPython( aFile, thePyScriptPath, theIsMultiFile, aTreatedObjects, KIND_STREAM );
270 aRes = aRes && dumpPartitionToPython( aFile, thePyScriptPath, theIsMultiFile, aTreatedObjects, KIND_CHANNEL );
271 aRes = aRes && dumpPartitionToPython( aFile, thePyScriptPath, theIsMultiFile, aTreatedObjects, KIND_DIGUE );
272 aRes = aRes && dumpPartitionToPython( aFile, thePyScriptPath, theIsMultiFile, aTreatedObjects, KIND_OBSTACLE );
273 aRes = aRes && dumpPartitionToPython( aFile, thePyScriptPath, theIsMultiFile, aTreatedObjects, KIND_LAND_COVER_MAP );
274 aRes = aRes && dumpPartitionToPython( aFile, thePyScriptPath, theIsMultiFile, aTreatedObjects, KIND_CALCULATION );
276 // Dump code to close python fuction
277 if ( aRes && theIsMultiFile )
279 QStringList aFooterScript;
280 aFooterScript << QString( "" );
281 aFooterScript << QString( " pass" );
282 HYDROData_Tool::WriteStringsToFile( aFile, aFooterScript );
288 QString HYDROData_Document::GetDocPyName() const
290 QString aDocName = PYTHON_DOC_NAME;
294 if ( DocumentId( this, aDocId ) )
295 aDocName += "_" + QString::number( aDocId );
301 QStringList HYDROData_Document::DumpToPython( const QString& thePyScriptPath,
302 MapOfTreatedObjects& theTreatedObjects,
303 const bool theIsMultiFile ) const
305 QString aDocName = GetDocPyName();
307 // Append document in to the map of treated objects to prevent names overlaping
308 theTreatedObjects.insert( aDocName, this );
311 if ( !DocumentId( this, aDocId ) )
314 QStringList aResScript;
316 aResScript << QString( "from HYDROPy import *" );
317 aResScript << QString( "from PyQt4.QtCore import *" );
318 aResScript << QString( "from PyQt4.QtGui import *" );
320 if ( theIsMultiFile )
322 aResScript << QString( "import salome" );
323 aResScript << QString( "" );
324 aResScript << QString( "def RebuildData( theStudy ):" );
325 aResScript << QString( " %1 = HYDROData_Document.Document( theStudy._get_StudyId() )" ).arg( aDocName );
329 aResScript << QString( "" );
330 aResScript << QString( "%1 = HYDROData_Document.Document( theStudy._get_StudyId() )" ).arg( aDocName );
336 bool HYDROData_Document::dumpPartitionToPython( QFile& theFile,
337 const QString& thePyScriptPath,
338 const bool theIsMultiFile,
339 MapOfTreatedObjects& theTreatedObjects,
340 const ObjectKind& theObjectKind ) const
342 if ( !theFile.isOpen() )
345 QTextStream anOutStream( &theFile );
349 HYDROData_Iterator anIterator( this, theObjectKind );
350 for( ; anIterator.More(); anIterator.Next() )
352 Handle(HYDROData_Entity) anObject = anIterator.Current();
353 if ( anObject.IsNull() )
356 QString anObjName = anObject->GetName();
357 if ( theTreatedObjects.contains( anObjName ) )
360 theTreatedObjects.insert( anObjName, anObject );
362 QStringList anObjDump = anObject->DumpToPython( thePyScriptPath, theTreatedObjects );
364 if ( theIsMultiFile )
366 // For multifile dump we use the function, see the document dump header
367 QStringList::iterator anIt = anObjDump.begin();
368 for ( ; anIt != anObjDump.end(); ++anIt )
369 anIt->prepend( " " );
372 HYDROData_Tool::WriteStringsToFile( theFile, anObjDump );
378 bool takeLastDigits( QString& theStr, int& aRes )
383 for ( int i = theStr.length() - 1; i >= 0; --i )
385 const QChar& aChar = theStr.at( i );
386 if ( !aChar.isDigit() )
389 anStrNum.prepend( aChar );
392 if ( anStrNum.isEmpty() )
395 theStr.remove( theStr.length() - anStrNum.length(), anStrNum.length() );
396 aRes = anStrNum.toInt();
401 bool isObjectNameLessThan( const QString& theStr1, const QString& theStr2 )
403 QString aStr1 = theStr1, aStr2 = theStr2;
405 int aNum1 = -1, aNum2 = -1;
406 if ( takeLastDigits( aStr1, aNum1 ) && takeLastDigits( aStr2, aNum2 ) )
408 if ( aStr1 == aStr2 )
409 return aNum1 < aNum2;
412 return theStr1 < theStr2;
415 HYDROData_SequenceOfObjects HYDROData_Document::GetObjectsLayerOrder(
416 const Standard_Boolean theIsAll ) const
418 HYDROData_SequenceOfObjects anOrder;
420 MapOfOrdered aMapOfOrdered;
421 MapOfUnordered aMapOfUnordered;
423 HYDROData_Iterator anIter( this );
424 for ( ; anIter.More(); anIter.Next() )
426 Handle(HYDROData_Entity) anObject = anIter.Current();
427 if ( anObject.IsNull() || !anObject->IsHas2dPrs() )
430 Standard_Integer anObjZLevel = -1;
431 if ( anObject->GetZLevel( anObjZLevel ) )
433 aMapOfOrdered.insert( anObjZLevel, anObject );
437 QString anObjName = anObject->GetName();
438 if ( anObjName.isEmpty() )
441 aMapOfUnordered.insert( anObjName, anObject );
445 MapOfOrdered::const_iterator anOrderedMapIt = aMapOfOrdered.constBegin();
446 for ( ; anOrderedMapIt != aMapOfOrdered.constEnd(); anOrderedMapIt++ )
448 const Handle(HYDROData_Entity)& anObject = anOrderedMapIt.value();
449 anOrder.Prepend( anObject );
454 QStringList aSortedNames = aMapOfUnordered.keys();
455 qSort( aSortedNames.begin(), aSortedNames.end(), isObjectNameLessThan );
457 for ( int i = 0; i < aSortedNames.length(); ++i )
459 QString anObjName = aSortedNames.value( i );
461 const Handle(HYDROData_Entity)& anObject = aMapOfUnordered.value( anObjName );
462 anOrder.Append( anObject );
469 void HYDROData_Document::SetObjectsLayerOrder( const HYDROData_SequenceOfObjects& theOrder )
471 // At first we remove previous model order
472 RemoveObjectsLayerOrder();
474 // Make new objects order
475 Standard_Integer aLevel = 0;
476 for ( int i = theOrder.Length(), n = 1; i >= n; --i )
478 const Handle(HYDROData_Entity)& anObject = theOrder.Value( i );
479 if ( anObject.IsNull() || !anObject->IsHas2dPrs() )
482 anObject->SetZLevel( aLevel++ );
486 void HYDROData_Document::Show( const Handle_HYDROData_Entity& theObject )
488 HYDROData_SequenceOfObjects anOrder;
489 anOrder.Append( theObject );
493 void HYDROData_Document::Show( const HYDROData_SequenceOfObjects& theObjects )
495 MapOfUnordered aMapOfUnordered;
497 for ( int i = 1, n = theObjects.Length(); i <= n; ++i )
499 const Handle(HYDROData_Entity)& anObject = theObjects.Value( i );
500 if ( anObject.IsNull() || !anObject->IsHas2dPrs() )
503 Standard_Integer anObjZLevel = -1;
504 if ( anObject->GetZLevel( anObjZLevel ) )
506 continue; // Skip objects that already have the z-level
510 QString anObjName = anObject->GetName();
511 if ( anObjName.isEmpty() )
514 aMapOfUnordered.insert( anObjName, anObject );
518 if ( aMapOfUnordered.isEmpty() )
519 return; // Nothing to show
521 Standard_Integer aTopId = 0;
523 HYDROData_SequenceOfObjects aModelOrder = GetObjectsLayerOrder( Standard_False );
524 if ( !aModelOrder.IsEmpty() )
526 const Handle(HYDROData_Entity)& anObject = aModelOrder.First();
527 anObject->GetZLevel( aTopId );
531 aTopId += aMapOfUnordered.size() - 1;
533 QStringList aSortedNames = aMapOfUnordered.keys();
534 qSort( aSortedNames.begin(), aSortedNames.end(), isObjectNameLessThan );
536 for ( int i = 0; i < aSortedNames.length(); ++i )
538 QString anObjName = aSortedNames.value( i );
540 const Handle(HYDROData_Entity)& anObject = aMapOfUnordered.value( anObjName );
541 anObject->SetZLevel( aTopId-- );
545 void HYDROData_Document::RemoveObjectsLayerOrder()
547 HYDROData_Iterator anIter( this );
548 for ( ; anIter.More(); anIter.Next() )
550 Handle(HYDROData_Entity) anObject = anIter.Current();
551 if ( anObject.IsNull() || !anObject->IsHas2dPrs() )
554 anObject->RemoveZLevel();
558 void HYDROData_Document::StartOperation()
563 void HYDROData_Document::CommitOperation(const TCollection_ExtendedString& theName)
565 if( !myDoc->CommitCommand() ) // it means that there were no modifications done
568 NewID(); // workaround: do something just to modify the document
569 myDoc->CommitCommand();
571 myTransactionsAfterSave++;
573 if( theName.Length() != 0 )
575 const TDF_DeltaList& aList = GetUndos();
576 if( !aList.IsEmpty() )
578 Handle(TDF_Delta) aDelta = aList.Last();
579 if( !aDelta.IsNull() )
580 aDelta->SetName( theName );
585 void HYDROData_Document::AbortOperation()
587 myDoc->AbortCommand();
590 bool HYDROData_Document::IsOperation()
592 return myDoc->HasOpenCommand() != 0;
595 bool HYDROData_Document::IsModified()
597 return myTransactionsAfterSave != 0;
600 bool HYDROData_Document::CanUndo()
602 return myDoc->GetAvailableUndos() > 0;
605 const TDF_DeltaList& HYDROData_Document::GetUndos()
607 return myDoc->GetUndos();
610 void HYDROData_Document::ClearUndos()
612 return myDoc->ClearUndos();
615 void HYDROData_Document::Undo()
618 myTransactionsAfterSave--;
621 bool HYDROData_Document::CanRedo()
623 return myDoc->GetAvailableRedos() > 0;
626 const TDF_DeltaList& HYDROData_Document::GetRedos()
628 return myDoc->GetRedos();
631 void HYDROData_Document::ClearRedos()
633 return myDoc->ClearRedos();
636 void HYDROData_Document::Redo()
639 myTransactionsAfterSave++;
642 Handle(HYDROData_Entity) HYDROData_Document::CreateObject( const ObjectKind theKind )
644 return HYDROData_Iterator::CreateObject( this, theKind );
647 Handle(HYDROData_Entity) HYDROData_Document::FindObjectByName(
648 const QString& theName,
649 const ObjectKind theObjectKind ) const
651 Handle(HYDROData_Entity) anObject;
652 if ( theName.isEmpty() )
655 QStringList aNamesList;
656 aNamesList << theName;
658 HYDROData_SequenceOfObjects aSeqOfObjs = FindObjectsByNames( aNamesList, theObjectKind );
659 if( aSeqOfObjs.IsEmpty() )
662 anObject = aSeqOfObjs.First();
666 HYDROData_SequenceOfObjects HYDROData_Document::FindObjectsByNames(
667 const QStringList& theNames,
668 const ObjectKind theObjectKind ) const
670 HYDROData_SequenceOfObjects aResSeq;
672 QStringList aNamesList = theNames;
674 HYDROData_Iterator anIter( this, theObjectKind );
675 for( ; anIter.More(); anIter.Next() )
677 Handle(HYDROData_Entity) anObject = anIter.Current();
678 if( anObject.IsNull() )
681 QString anObjName = anObject->GetName();
682 if ( anObjName.isEmpty() || !aNamesList.contains( anObjName ) )
685 aResSeq.Append( anObject );
687 aNamesList.removeAll( anObjName );
688 if ( aNamesList.isEmpty() )
695 HYDROData_Document::HYDROData_Document()
697 HYDROData_Application::GetApplication()->NewDocument("BinOcaf", myDoc);
698 myDoc->SetUndoLimit(UNDO_LIMIT);
699 NewID(); // needed to have at least one attribute in initial document to avoid errors
700 myTransactionsAfterSave = 0;
704 myInterpolatorsFactory = 0;
707 HYDROData_Document::HYDROData_Document(const Handle(TDocStd_Document)& theDoc)
710 myTransactionsAfterSave = 0;
714 myInterpolatorsFactory = 0;
717 HYDROData_Document::~HYDROData_Document()
721 int HYDROData_Document::NewID()
723 TDF_Label anIDLab = myDoc->Main().FindChild(TAG_PROPS).
724 FindChild(TAG_PROPS_NEW_ID);
725 Handle(TDataStd_Integer) anInt;
726 if (!anIDLab.FindAttribute(TDataStd_Integer::GetID(), anInt)) {
727 anInt = TDataStd_Integer::Set(anIDLab, 0);
729 // just increment value and return
730 anInt->Set(anInt->Get() + 1);
734 TDF_Label HYDROData_Document::LabelOfObjects()
736 return myDoc->Main().FindChild(TAG_OBJECTS);
739 TDF_Label HYDROData_Document::LabelOfLocalCS() const
741 return myDoc->Main().FindChild(TAG_LOCAL_CS);
744 void HYDROData_Document::GetLocalCS( double& theLX, double& theLY ) const
746 TDF_Label aLocalCSLab = LabelOfLocalCS();
748 Handle( TDataXtd_Position ) aLocalCS;
749 if( aLocalCSLab.FindAttribute( TDataXtd_Position::GetID(), aLocalCS ) )
751 gp_Pnt aLocalCS3d = aLocalCS->GetPosition();
752 theLX = aLocalCS3d.X();
753 theLY = aLocalCS3d.Y();
757 theLX = DEFAULT_LOCAL_CS.X();
758 theLY = DEFAULT_LOCAL_CS.Y();
762 void HYDROData_Document::SetLocalCS( double theLX, double theLY )
766 // update the local CS data in attribute
767 TDF_Label aLocalCSLab = LabelOfLocalCS();
768 Handle( TDataXtd_Position ) aLocalCS;
769 if( !aLocalCSLab.FindAttribute( TDataXtd_Position::GetID(), aLocalCS ) )
770 aLocalCS = TDataXtd_Position::Set( aLocalCSLab );
772 gp_Pnt aLocalCS3d( theLX, theLY, 0 );
773 aLocalCS->SetPosition( aLocalCS3d );
775 // calculate delta for coordinates
776 double aDX = myLX - theLX;
777 double aDY = myLY - theLY;
779 // update the local CS data in internal fields
783 //update all objects in the document
784 HYDROData_Iterator anIterator( this, KIND_UNKNOWN );
785 for( ; anIterator.More(); anIterator.Next() )
786 anIterator.Current()->UpdateLocalCS( aDX, aDY );
789 void HYDROData_Document::UpdateLCSFields() const
791 if( myLX >= 0 && myLY >= 0 )
795 GetLocalCS( aLX, aLY );
796 HYDROData_Document* aThat = const_cast<HYDROData_Document*>( this );
801 void HYDROData_Document::Transform( double& X, double& Y, bool IsToLocalCS ) const
816 void HYDROData_Document::Transform( gp_Pnt& thePnt, bool IsToLocalCS ) const
818 double X = thePnt.X();
819 double Y = thePnt.Y();
820 double Z = thePnt.Z();
821 Transform( X, Y, IsToLocalCS );
822 thePnt = gp_Pnt( X, Y, Z );
825 void HYDROData_Document::Transform( gp_XYZ& thePnt, bool IsToLocalCS ) const
827 double X = thePnt.X();
828 double Y = thePnt.Y();
829 double Z = thePnt.Z();
830 Transform( X, Y, IsToLocalCS );
831 thePnt = gp_XYZ( X, Y, Z );
834 void HYDROData_Document::Transform( double& X, double& Y, double& Z, bool IsToLocalCS ) const
836 Transform( X, Y, IsToLocalCS );
839 void HYDROData_Document::Transform( gp_XY& thePnt, bool IsToLocalCS ) const
841 double X = thePnt.X();
842 double Y = thePnt.Y();
843 Transform( X, Y, IsToLocalCS );
844 thePnt = gp_XY( X, Y );
847 HYDROData_InterpolatorsFactory* HYDROData_Document::GetInterpolatorsFactory()
849 if ( !myInterpolatorsFactory ) {
850 myInterpolatorsFactory = new HYDROData_InterpolatorsFactory();
853 return myInterpolatorsFactory;
856 HYDROData_IProfilesInterpolator* HYDROData_Document::GetInterpolator( const TCollection_AsciiString& theName ) const
858 HYDROData_IProfilesInterpolator* anInterpolator = NULL;
860 HYDROData_Document* aThat = const_cast<HYDROData_Document*>( this );
861 HYDROData_InterpolatorsFactory* aFactory = aThat->GetInterpolatorsFactory();
863 anInterpolator = aFactory->GetInterpolator( theName );
866 return anInterpolator;
869 NCollection_Sequence<TCollection_AsciiString> HYDROData_Document::GetInterpolatorNames() const
871 NCollection_Sequence<TCollection_AsciiString> aNames;
873 HYDROData_Document* aThat = const_cast<HYDROData_Document*>( this );
874 HYDROData_InterpolatorsFactory* aFactory = aThat->GetInterpolatorsFactory();
876 aNames = aFactory->GetInterpolatorNames();
882 QColor HYDROData_Document::GetAssociatedColor( const QString& theStricklerType, const Handle(HYDROData_StricklerTable)& theTable ) const
884 if( !theTable.IsNull() && theTable->HasType( theStricklerType ) )
885 return theTable->GetColor( theStricklerType );
887 HYDROData_Iterator anIt( this, KIND_STRICKLER_TABLE );
888 for( ; anIt.More(); anIt.Next() )
890 Handle(HYDROData_StricklerTable) aTable = Handle(HYDROData_StricklerTable)::DownCast( anIt.Current() );
891 if( aTable->HasType( theStricklerType ) )
892 return aTable->GetColor( theStricklerType );
897 void HYDROData_Document::CollectQGISValues( const QString& theAttrName,
898 QStringList& theAttrValues,
899 QStringList& theStricklerTypes ) const
901 HYDROData_Iterator It( this, KIND_STRICKLER_TABLE );
902 for( ; It.More(); It.Next() )
904 Handle(HYDROData_StricklerTable) aTable = Handle(HYDROData_StricklerTable)::DownCast( It.Current() );
905 if( !aTable.IsNull() && aTable->GetAttrName()==theAttrName )
907 theAttrValues.clear();
908 theStricklerTypes = aTable->GetTypes();
909 foreach( QString aType, theStricklerTypes )
911 QString anAttrValue = aTable->GetAttrValue( aType );
912 theAttrValues.append( anAttrValue );