#include "HYDROData_Image.h"
#include "HYDROData_Iterator.h"
#include "HYDROData_NaturalObject.h"
+#include "HYDROData_ShapesGroup.h"
#include <QFile>
#include <QStringList>
#include <BRepAdaptor_Surface.hxx>
#include <BRepTopAdaptor_FClass2d.hxx>
#include <BRep_Tool.hxx>
+#include <Geom_Curve.hxx>
+#include <TopoDS.hxx>
+#include <TopoDS_Wire.hxx>
+#include <TopExp_Explorer.hxx>
static int aMaxNameId = std::numeric_limits<int>::max();
anOutStream << aWriteStr << theSep << theSep;
}
-void HYDROData_Tool::SetMustBeUpdatedObjects(
- const Handle(HYDROData_Document)& theDoc )
-{
- bool anIsChanged = true;
-
- // iterate until there is no changes because objects on all level of dependency must be updated
- while ( anIsChanged )
- {
- anIsChanged = false;
-
- HYDROData_Iterator anIter( theDoc );
- for ( ; anIter.More(); anIter.Next() )
- {
- Handle(HYDROData_Entity) anObject = anIter.Current();
- if ( anObject.IsNull() || anObject->IsMustBeUpdated() )
- continue;
-
- HYDROData_SequenceOfObjects aRefSeq = anObject->GetAllReferenceObjects();
- for ( int i = 1, n = aRefSeq.Length(); i <= n; ++i )
- {
- Handle(HYDROData_Entity) aRefObject = aRefSeq.Value( i );
- if ( aRefObject.IsNull() || !aRefObject->IsMustBeUpdated() )
- continue;
-
- anObject->SetToUpdate( true );
- anIsChanged = true;
- break;
- }
- }
- }
-}
-
QString HYDROData_Tool::GenerateObjectName( const Handle(HYDROData_Document)& theDoc,
const QString& thePrefix,
const QStringList& theUsedNames,
BRepTopAdaptor_FClass2d aClassifier( theFace, toluv );
aState = aClassifier.Perform( gp_Pnt2d(aU1, aV1), Standard_False );
return aState;
+}
+
+double HYDROData_Tool::GetAltitudeForEdge( const TopoDS_Edge& theEdge,
+ const gp_XY& thePoint,
+ double theParameterTolerance,
+ double theSquareDistanceTolerance,
+ double theInvalidAltitude )
+{
+ double aFirst, aLast;
+ Handle(Geom_Curve) aCurve = BRep_Tool::Curve( theEdge, aFirst, aLast );
+ if( aCurve.IsNull() )
+ return theInvalidAltitude;
+
+ gp_Pnt aFirstPnt, aLastPnt;
+
+ aCurve->D0( aFirst, aFirstPnt );
+ aCurve->D0( aLast, aLastPnt );
+
+ gp_Pnt2d aFirstPnt2d( aFirstPnt.X(), aFirstPnt.Y() );
+ gp_Pnt2d aLastPnt2d( aLastPnt.X(), aLastPnt.Y() );
+
+ double aFirstDist = 0;
+ double aLastDist = aFirstPnt2d.SquareDistance( aLastPnt2d );
+ double aNecDist = aFirstPnt2d.SquareDistance( thePoint );
+
+ while( fabs( aLast - aFirst ) > theParameterTolerance )
+ {
+ double aMid = ( aFirst + aLast ) / 2;
+ gp_Pnt aMidPnt;
+ aCurve->D0( aMid, aMidPnt );
+ double aDist = aFirstPnt2d.SquareDistance( gp_Pnt2d( aMidPnt.X(), aMidPnt.Y() ) );
+
+ if( aDist < aNecDist )
+ aFirst = aMid;
+ else
+ aLast = aMid;
+ }
+
+ double aMid = ( aFirst + aLast ) / 2;
+ gp_Pnt aMidPnt;
+ aCurve->D0( aMid, aMidPnt );
+
+ gp_Pnt2d aMidPnt2d( aMidPnt.X(), aMidPnt.Y() );
+ if( aMidPnt2d.SquareDistance( thePoint ) < theSquareDistanceTolerance )
+ return aMidPnt.Z();
+ else
+ return theInvalidAltitude;
+}
+
+double HYDROData_Tool::GetAltitudeForWire( const TopoDS_Wire& theWire,
+ const gp_XY& thePoint,
+ double theParameterTolerance,
+ double theSquareDistanceTolerance,
+ double theInvalidAltitude )
+{
+ TopExp_Explorer anExp( theWire, TopAbs_EDGE );
+ for( ; anExp.More(); anExp.Next() )
+ {
+ double anAltitude = GetAltitudeForEdge( TopoDS::Edge( anExp.Current() ), thePoint,
+ theParameterTolerance, theSquareDistanceTolerance, theInvalidAltitude );
+ if( anAltitude != theInvalidAltitude )
+ return anAltitude;
+ }
+ return theInvalidAltitude;
+}
+
+TopoDS_Shape HYDROData_Tool::getFirstShapeFromGroup( const HYDROData_SequenceOfObjects& theGroups,
+ const int theGroupId )
+{
+ TopoDS_Shape aResShape;
+ if ( theGroupId < 1 || theGroupId > theGroups.Length() )
+ return aResShape;
+
+ Handle(HYDROData_ShapesGroup) aGroup =
+ Handle(HYDROData_ShapesGroup)::DownCast( theGroups.Value( theGroupId ) );
+ if ( aGroup.IsNull() )
+ return aResShape;
+
+ TopTools_SequenceOfShape aGroupShapes;
+ aGroup->GetShapes( aGroupShapes );
+
+ if ( !aGroupShapes.IsEmpty() )
+ aResShape = aGroupShapes.First();
+
+ return aResShape;
}
\ No newline at end of file