// Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
-//
+//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
+// License as published by the Free Software Foundation; either
// version 2.1 of the License.
-//
-// This library is distributed in the hope that it will be useful
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+//
+// This library is distributed in the hope that it will be useful
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
-// See http://www.salome-platform.org/
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
+
#include <Standard_Stream.hxx>
#include <GEOMImpl_IMeasureOperations.hxx>
#include <GEOMImpl_MeasureDriver.hxx>
#include <GEOMImpl_IMeasure.hxx>
+#include <GEOMAlgo_ShapeInfo.hxx>
+#include <GEOMAlgo_ShapeInfoFiller.hxx>
+
#include <GEOM_Function.hxx>
#include <GEOM_PythonDump.hxx>
-#include "utilities.h"
+#include <utilities.h>
#include <OpUtil.hxx>
#include <Utils_ExceptHandlers.hxx>
+// OCCT Includes
#include <TFunction_DriverTable.hxx>
#include <TFunction_Driver.hxx>
#include <TFunction_Logbook.hxx>
#include <TDF_Tool.hxx>
#include <BRep_Tool.hxx>
+#include <BRepAdaptor_Surface.hxx>
+#include <BRepBndLib.hxx>
#include <BRepCheck.hxx>
#include <BRepCheck_Result.hxx>
#include <BRepCheck_ListIteratorOfListOfStatus.hxx>
-#include <BRepGProp.hxx>
-#include <BRepBndLib.hxx>
#include <BRepExtrema_DistShapeShape.hxx>
+#include <BRepGProp.hxx>
+#include <BRepTools.hxx>
#include <Bnd_Box.hxx>
#include <TopTools_ListOfShape.hxx>
#include <TopTools_ListIteratorOfListOfShape.hxx>
+#include <GeomAbs_SurfaceType.hxx>
+#include <Geom_Surface.hxx>
+#include <Geom_Plane.hxx>
+#include <Geom_SphericalSurface.hxx>
+#include <Geom_CylindricalSurface.hxx>
+#include <Geom_ToroidalSurface.hxx>
+#include <Geom_ConicalSurface.hxx>
+#include <Geom_SurfaceOfLinearExtrusion.hxx>
+#include <Geom_SurfaceOfRevolution.hxx>
+#include <Geom_BezierSurface.hxx>
+#include <Geom_BSplineSurface.hxx>
+#include <Geom_RectangularTrimmedSurface.hxx>
+#include <Geom_OffsetSurface.hxx>
+#include <Geom_Line.hxx>
+
+#include <gp_Pln.hxx>
+#include <gp_Lin.hxx>
+
+#include <Standard_Failure.hxx>
#include <Standard_ErrorHandler.hxx> // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC
//=============================================================================
/*!
- * constructor:
+ * Constructor
*/
//=============================================================================
GEOMImpl_IMeasureOperations::GEOMImpl_IMeasureOperations (GEOM_Engine* theEngine, int theDocID)
//=============================================================================
/*!
- * destructor
+ * Destructor
*/
//=============================================================================
GEOMImpl_IMeasureOperations::~GEOMImpl_IMeasureOperations()
MESSAGE("GEOMImpl_IMeasureOperations::~GEOMImpl_IMeasureOperations");
}
+//=============================================================================
+/*! Get kind and parameters of the given shape.
+ */
+//=============================================================================
+GEOMImpl_IMeasureOperations::ShapeKind GEOMImpl_IMeasureOperations::KindOfShape
+ (Handle(GEOM_Object) theShape,
+ Handle(TColStd_HSequenceOfInteger)& theIntegers,
+ Handle(TColStd_HSequenceOfReal)& theDoubles)
+{
+ SetErrorCode(KO);
+ ShapeKind aKind = SK_NO_SHAPE;
+
+ if (theIntegers.IsNull()) theIntegers = new TColStd_HSequenceOfInteger;
+ else theIntegers->Clear();
+
+ if (theDoubles.IsNull()) theDoubles = new TColStd_HSequenceOfReal;
+ else theDoubles->Clear();
+
+ if (theShape.IsNull())
+ return aKind;
+
+ Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
+ if (aRefShape.IsNull()) return aKind;
+
+ TopoDS_Shape aShape = aRefShape->GetValue();
+ if (aShape.IsNull()) return aKind;
+
+ // Call algorithm
+ GEOMAlgo_ShapeInfoFiller aSF;
+ aSF.SetShape(aShape);
+ aSF.Perform();
+ Standard_Integer iErr = aSF.ErrorStatus();
+ if (iErr) {
+ SetErrorCode("Error in GEOMAlgo_ShapeInfoFiller");
+ return SK_NO_SHAPE;
+ }
+ const GEOMAlgo_ShapeInfo& anInfo = aSF.Info();
+
+ // Interprete results
+ TopAbs_ShapeEnum aType = anInfo.Type();
+ switch (aType)
+ {
+ case TopAbs_COMPOUND:
+ case TopAbs_COMPSOLID:
+ {
+ // (+) geompy.kind.COMPOUND nb_solids nb_faces nb_edges nb_vertices
+ // (+) geompy.kind.COMPSOLID nb_solids nb_faces nb_edges nb_vertices
+ // ??? "nb_faces" - all faces or only 'standalone' faces?
+ if (aType == TopAbs_COMPOUND)
+ aKind = SK_COMPOUND;
+ else
+ aKind = SK_COMPSOLID;
+
+ //theIntegers->Append(anInfo.NbSubShapes(TopAbs_COMPOUND));
+ //theIntegers->Append(anInfo.NbSubShapes(TopAbs_COMPSOLID));
+ theIntegers->Append(anInfo.NbSubShapes(TopAbs_SOLID));
+ theIntegers->Append(anInfo.NbSubShapes(TopAbs_FACE));
+ theIntegers->Append(anInfo.NbSubShapes(TopAbs_EDGE));
+ theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
+ }
+ break;
+
+ case TopAbs_SHELL:
+ {
+ // (+) geompy.kind.SHELL geompy.info.closed nb_faces nb_edges nb_vertices
+ // (+) geompy.kind.SHELL geompy.info.unclosed nb_faces nb_edges nb_vertices
+ aKind = SK_SHELL;
+
+ theIntegers->Append((int)anInfo.KindOfClosed());
+
+ theIntegers->Append(anInfo.NbSubShapes(TopAbs_FACE));
+ theIntegers->Append(anInfo.NbSubShapes(TopAbs_EDGE));
+ theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
+ }
+ break;
+
+ case TopAbs_WIRE:
+ {
+ // (+) geompy.kind.WIRE geompy.info.closed nb_edges nb_vertices
+ // (+) geompy.kind.WIRE geompy.info.unclosed nb_edges nb_vertices
+ aKind = SK_WIRE;
+
+ theIntegers->Append((int)anInfo.KindOfClosed());
+
+ theIntegers->Append(anInfo.NbSubShapes(TopAbs_EDGE));
+ theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
+ }
+ break;
+
+ case TopAbs_SOLID:
+ {
+ aKind = SK_SOLID;
+
+ GEOMAlgo_KindOfName aKN = anInfo.KindOfName();
+ switch (aKN)
+ {
+ case GEOMAlgo_KN_SPHERE:
+ // (+) geompy.kind.SPHERE xc yc zc R
+ {
+ aKind = SK_SPHERE;
+
+ gp_Pnt aC = anInfo.Location();
+ theDoubles->Append(aC.X());
+ theDoubles->Append(aC.Y());
+ theDoubles->Append(aC.Z());
+
+ theDoubles->Append(anInfo.Radius1());
+ }
+ break;
+ case GEOMAlgo_KN_CYLINDER:
+ // (+) geompy.kind.CYLINDER xb yb zb dx dy dz R H
+ {
+ aKind = SK_CYLINDER;
+
+ gp_Pnt aC = anInfo.Location();
+ theDoubles->Append(aC.X());
+ theDoubles->Append(aC.Y());
+ theDoubles->Append(aC.Z());
+
+ gp_Ax3 anAx3 = anInfo.Position();
+ gp_Dir aD = anAx3.Direction();
+ theDoubles->Append(aD.X());
+ theDoubles->Append(aD.Y());
+ theDoubles->Append(aD.Z());
+
+ theDoubles->Append(anInfo.Radius1());
+ theDoubles->Append(anInfo.Height());
+ }
+ break;
+ case GEOMAlgo_KN_BOX:
+ // (+) geompy.kind.BOX xc yc zc ax ay az
+ {
+ aKind = SK_BOX;
+
+ gp_Pnt aC = anInfo.Location();
+ theDoubles->Append(aC.X());
+ theDoubles->Append(aC.Y());
+ theDoubles->Append(aC.Z());
+
+ gp_Ax3 anAx3 = anInfo.Position();
+ gp_Dir aD = anAx3.Direction();
+ gp_Dir aX = anAx3.XDirection();
+
+ // ax ay az
+ if (aD.IsParallel(gp::DZ(), Precision::Angular()) &&
+ aX.IsParallel(gp::DX(), Precision::Angular())) {
+ theDoubles->Append(anInfo.Length()); // ax'
+ theDoubles->Append(anInfo.Width()); // ay'
+ theDoubles->Append(anInfo.Height()); // az'
+ }
+ else if (aD.IsParallel(gp::DZ(), Precision::Angular()) &&
+ aX.IsParallel(gp::DY(), Precision::Angular())) {
+ theDoubles->Append(anInfo.Width()); // ay'
+ theDoubles->Append(anInfo.Length()); // ax'
+ theDoubles->Append(anInfo.Height()); // az'
+ }
+ else if (aD.IsParallel(gp::DX(), Precision::Angular()) &&
+ aX.IsParallel(gp::DZ(), Precision::Angular())) {
+ theDoubles->Append(anInfo.Height()); // az'
+ theDoubles->Append(anInfo.Width()); // ay'
+ theDoubles->Append(anInfo.Length()); // ax'
+ }
+ else if (aD.IsParallel(gp::DX(), Precision::Angular()) &&
+ aX.IsParallel(gp::DY(), Precision::Angular())) {
+ theDoubles->Append(anInfo.Height()); // az'
+ theDoubles->Append(anInfo.Length()); // ax'
+ theDoubles->Append(anInfo.Width()); // ay'
+ }
+ else if (aD.IsParallel(gp::DY(), Precision::Angular()) &&
+ aX.IsParallel(gp::DZ(), Precision::Angular())) {
+ theDoubles->Append(anInfo.Width()); // ay'
+ theDoubles->Append(anInfo.Height()); // az'
+ theDoubles->Append(anInfo.Length()); // ax'
+ }
+ else if (aD.IsParallel(gp::DY(), Precision::Angular()) &&
+ aX.IsParallel(gp::DX(), Precision::Angular())) {
+ theDoubles->Append(anInfo.Length()); // ax'
+ theDoubles->Append(anInfo.Height()); // az'
+ theDoubles->Append(anInfo.Width()); // ay'
+ }
+ else {
+ // (+) geompy.kind.ROTATED_BOX xo yo zo zx zy zz xx xy xz ax ay az
+ aKind = SK_ROTATED_BOX;
+
+ // Direction and XDirection
+ theDoubles->Append(aD.X());
+ theDoubles->Append(aD.Y());
+ theDoubles->Append(aD.Z());
+
+ theDoubles->Append(aX.X());
+ theDoubles->Append(aX.Y());
+ theDoubles->Append(aX.Z());
+
+ // ax ay az
+ theDoubles->Append(anInfo.Length());
+ theDoubles->Append(anInfo.Width());
+ theDoubles->Append(anInfo.Height());
+ }
+ }
+ break;
+ case GEOMAlgo_KN_TORUS:
+ // (+) geompy.kind.TORUS xc yc zc dx dy dz R_1 R_2
+ {
+ aKind = SK_TORUS;
+
+ gp_Pnt aO = anInfo.Location();
+ theDoubles->Append(aO.X());
+ theDoubles->Append(aO.Y());
+ theDoubles->Append(aO.Z());
+
+ gp_Ax3 anAx3 = anInfo.Position();
+ gp_Dir aD = anAx3.Direction();
+ theDoubles->Append(aD.X());
+ theDoubles->Append(aD.Y());
+ theDoubles->Append(aD.Z());
+
+ theDoubles->Append(anInfo.Radius1());
+ theDoubles->Append(anInfo.Radius2());
+ }
+ break;
+ case GEOMAlgo_KN_CONE:
+ // (+) geompy.kind.CONE xb yb zb dx dy dz R_1 R_2 H
+ {
+ aKind = SK_CONE;
+
+ gp_Pnt aO = anInfo.Location();
+ theDoubles->Append(aO.X());
+ theDoubles->Append(aO.Y());
+ theDoubles->Append(aO.Z());
+
+ gp_Ax3 anAx3 = anInfo.Position();
+ gp_Dir aD = anAx3.Direction();
+ theDoubles->Append(aD.X());
+ theDoubles->Append(aD.Y());
+ theDoubles->Append(aD.Z());
+
+ theDoubles->Append(anInfo.Radius1());
+ theDoubles->Append(anInfo.Radius2());
+ theDoubles->Append(anInfo.Height());
+ }
+ break;
+ case GEOMAlgo_KN_POLYHEDRON:
+ // (+) geompy.kind.POLYHEDRON nb_faces nb_edges nb_vertices
+ {
+ aKind = SK_POLYHEDRON;
+
+ theIntegers->Append(anInfo.NbSubShapes(TopAbs_FACE));
+ theIntegers->Append(anInfo.NbSubShapes(TopAbs_EDGE));
+ theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
+ }
+ break;
+ default:
+ // (+) geompy.kind.SOLID nb_faces nb_edges nb_vertices
+ {
+ theIntegers->Append(anInfo.NbSubShapes(TopAbs_FACE));
+ theIntegers->Append(anInfo.NbSubShapes(TopAbs_EDGE));
+ theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
+ }
+ }
+ }
+ break;
+
+ case TopAbs_FACE:
+ {
+ aKind = SK_FACE;
+
+ GEOMAlgo_KindOfName aKN = anInfo.KindOfName();
+ switch (aKN) {
+ case GEOMAlgo_KN_SPHERE:
+ // (+) geompy.kind.SPHERE2D xc yc zc R
+ {
+ aKind = SK_SPHERE2D;
+
+ gp_Pnt aC = anInfo.Location();
+ theDoubles->Append(aC.X());
+ theDoubles->Append(aC.Y());
+ theDoubles->Append(aC.Z());
+
+ theDoubles->Append(anInfo.Radius1());
+ }
+ break;
+ case GEOMAlgo_KN_CYLINDER:
+ // (+) geompy.kind.CYLINDER2D xb yb zb dx dy dz R H
+ {
+ aKind = SK_CYLINDER2D;
+
+ gp_Pnt aO = anInfo.Location();
+ theDoubles->Append(aO.X());
+ theDoubles->Append(aO.Y());
+ theDoubles->Append(aO.Z());
+
+ gp_Ax3 anAx3 = anInfo.Position();
+ gp_Dir aD = anAx3.Direction();
+ theDoubles->Append(aD.X());
+ theDoubles->Append(aD.Y());
+ theDoubles->Append(aD.Z());
+
+ theDoubles->Append(anInfo.Radius1());
+ theDoubles->Append(anInfo.Height());
+ }
+ break;
+ case GEOMAlgo_KN_TORUS:
+ // (+) geompy.kind.TORUS2D xc yc zc dx dy dz R_1 R_2
+ {
+ aKind = SK_TORUS2D;
+
+ gp_Pnt aO = anInfo.Location();
+ theDoubles->Append(aO.X());
+ theDoubles->Append(aO.Y());
+ theDoubles->Append(aO.Z());
+
+ gp_Ax3 anAx3 = anInfo.Position();
+ gp_Dir aD = anAx3.Direction();
+ theDoubles->Append(aD.X());
+ theDoubles->Append(aD.Y());
+ theDoubles->Append(aD.Z());
+
+ theDoubles->Append(anInfo.Radius1());
+ theDoubles->Append(anInfo.Radius2());
+ }
+ break;
+ case GEOMAlgo_KN_CONE:
+ // (+) geompy.kind.CONE2D xc yc zc dx dy dz R_1 R_2 H
+ {
+ aKind = SK_CONE2D;
+
+ gp_Pnt aO = anInfo.Location();
+ theDoubles->Append(aO.X());
+ theDoubles->Append(aO.Y());
+ theDoubles->Append(aO.Z());
+
+ gp_Ax3 anAx3 = anInfo.Position();
+ gp_Dir aD = anAx3.Direction();
+ theDoubles->Append(aD.X());
+ theDoubles->Append(aD.Y());
+ theDoubles->Append(aD.Z());
+
+ theDoubles->Append(anInfo.Radius1());
+ theDoubles->Append(anInfo.Radius2());
+ theDoubles->Append(anInfo.Height());
+ }
+ break;
+ case GEOMAlgo_KN_DISKCIRCLE:
+ // (+) geompy.kind.DISK_CIRCLE xc yc zc dx dy dz R
+ {
+ aKind = SK_DISK_CIRCLE;
+
+ gp_Pnt aC = anInfo.Location();
+ theDoubles->Append(aC.X());
+ theDoubles->Append(aC.Y());
+ theDoubles->Append(aC.Z());
+
+ gp_Ax3 anAx3 = anInfo.Position();
+ gp_Dir aD = anAx3.Direction();
+ theDoubles->Append(aD.X());
+ theDoubles->Append(aD.Y());
+ theDoubles->Append(aD.Z());
+
+ theDoubles->Append(anInfo.Radius1());
+ }
+ break;
+ case GEOMAlgo_KN_DISKELLIPSE:
+ // (+) geompy.kind.DISK_ELLIPSE xc yc zc dx dy dz R_1 R_2
+ {
+ aKind = SK_DISK_ELLIPSE;
+
+ gp_Pnt aC = anInfo.Location();
+ theDoubles->Append(aC.X());
+ theDoubles->Append(aC.Y());
+ theDoubles->Append(aC.Z());
+
+ gp_Ax3 anAx3 = anInfo.Position();
+ gp_Dir aD = anAx3.Direction();
+ theDoubles->Append(aD.X());
+ theDoubles->Append(aD.Y());
+ theDoubles->Append(aD.Z());
+
+ theDoubles->Append(anInfo.Radius1());
+ theDoubles->Append(anInfo.Radius2());
+ }
+ break;
+ case GEOMAlgo_KN_RECTANGLE:
+ case GEOMAlgo_KN_TRIANGLE:
+ case GEOMAlgo_KN_QUADRANGLE:
+ case GEOMAlgo_KN_POLYGON:
+ // (+) geompy.kind.POLYGON xo yo zo dx dy dz nb_edges nb_vertices
+ {
+ aKind = SK_POLYGON;
+
+ gp_Pnt aO = anInfo.Location();
+ theDoubles->Append(aO.X());
+ theDoubles->Append(aO.Y());
+ theDoubles->Append(aO.Z());
+
+ gp_Ax3 anAx3 = anInfo.Position();
+ gp_Dir aD = anAx3.Direction();
+ theDoubles->Append(aD.X());
+ theDoubles->Append(aD.Y());
+ theDoubles->Append(aD.Z());
+
+ theIntegers->Append(anInfo.NbSubShapes(TopAbs_EDGE));
+ theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
+ }
+ break;
+ case GEOMAlgo_KN_PLANE: // infinite
+ // (+) geompy.kind.PLANE xo yo zo dx dy dz
+ {
+ aKind = SK_PLANE;
+
+ gp_Pnt aC = anInfo.Location();
+ theDoubles->Append(aC.X());
+ theDoubles->Append(aC.Y());
+ theDoubles->Append(aC.Z());
+
+ gp_Ax3 anAx3 = anInfo.Position();
+ gp_Dir aD = anAx3.Direction();
+ theDoubles->Append(aD.X());
+ theDoubles->Append(aD.Y());
+ theDoubles->Append(aD.Z());
+ }
+ break;
+ default:
+ if (anInfo.KindOfShape() == GEOMAlgo_KS_PLANE) {
+ // (+) geompy.kind.PLANAR xo yo zo dx dy dz nb_edges nb_vertices
+
+ aKind = SK_PLANAR;
+
+ gp_Pnt aC = anInfo.Location();
+ theDoubles->Append(aC.X());
+ theDoubles->Append(aC.Y());
+ theDoubles->Append(aC.Z());
+
+ gp_Ax3 anAx3 = anInfo.Position();
+ gp_Dir aD = anAx3.Direction();
+ theDoubles->Append(aD.X());
+ theDoubles->Append(aD.Y());
+ theDoubles->Append(aD.Z());
+
+ theIntegers->Append(anInfo.NbSubShapes(TopAbs_EDGE));
+ theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
+ }
+ else {
+ // ??? geompy.kind.FACE nb_edges nb_vertices _surface_type_id_
+ // (+) geompy.kind.FACE nb_edges nb_vertices
+
+ theIntegers->Append(anInfo.NbSubShapes(TopAbs_EDGE));
+ theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
+ }
+ }
+ }
+ break;
+
+ case TopAbs_EDGE:
+ {
+ aKind = SK_EDGE;
+
+ GEOMAlgo_KindOfName aKN = anInfo.KindOfName();
+ switch (aKN) {
+ case GEOMAlgo_KN_CIRCLE:
+ {
+ // (+) geompy.kind.CIRCLE xc yc zc dx dy dz R
+ aKind = SK_CIRCLE;
+
+ gp_Pnt aC = anInfo.Location();
+ theDoubles->Append(aC.X());
+ theDoubles->Append(aC.Y());
+ theDoubles->Append(aC.Z());
+
+ gp_Ax3 anAx3 = anInfo.Position();
+ gp_Dir aD = anAx3.Direction();
+ theDoubles->Append(aD.X());
+ theDoubles->Append(aD.Y());
+ theDoubles->Append(aD.Z());
+
+ theDoubles->Append(anInfo.Radius1());
+ }
+ break;
+ case GEOMAlgo_KN_ARCCIRCLE:
+ {
+ // (+) geompy.kind.ARC_CIRCLE xc yc zc dx dy dz R x1 y1 z1 x2 y2 z2
+ aKind = SK_ARC_CIRCLE;
+
+ gp_Pnt aC = anInfo.Location();
+ theDoubles->Append(aC.X());
+ theDoubles->Append(aC.Y());
+ theDoubles->Append(aC.Z());
+
+ gp_Ax3 anAx3 = anInfo.Position();
+ gp_Dir aD = anAx3.Direction();
+ theDoubles->Append(aD.X());
+ theDoubles->Append(aD.Y());
+ theDoubles->Append(aD.Z());
+
+ theDoubles->Append(anInfo.Radius1());
+
+ gp_Pnt aP1 = anInfo.Pnt1();
+ theDoubles->Append(aP1.X());
+ theDoubles->Append(aP1.Y());
+ theDoubles->Append(aP1.Z());
+
+ gp_Pnt aP2 = anInfo.Pnt2();
+ theDoubles->Append(aP2.X());
+ theDoubles->Append(aP2.Y());
+ theDoubles->Append(aP2.Z());
+ }
+ break;
+ case GEOMAlgo_KN_ELLIPSE:
+ {
+ // (+) geompy.kind.ELLIPSE xc yc zc dx dy dz R_1 R_2
+ aKind = SK_ELLIPSE;
+
+ gp_Pnt aC = anInfo.Location();
+ theDoubles->Append(aC.X());
+ theDoubles->Append(aC.Y());
+ theDoubles->Append(aC.Z());
+
+ gp_Ax3 anAx3 = anInfo.Position();
+ gp_Dir aD = anAx3.Direction();
+ theDoubles->Append(aD.X());
+ theDoubles->Append(aD.Y());
+ theDoubles->Append(aD.Z());
+
+ theDoubles->Append(anInfo.Radius1());
+ theDoubles->Append(anInfo.Radius2());
+ }
+ break;
+ case GEOMAlgo_KN_ARCELLIPSE:
+ {
+ // (+) geompy.kind.ARC_ELLIPSE xc yc zc dx dy dz R_1 R_2 x1 y1 z1 x2 y2 z2
+ aKind = SK_ARC_ELLIPSE;
+
+ gp_Pnt aC = anInfo.Location();
+ theDoubles->Append(aC.X());
+ theDoubles->Append(aC.Y());
+ theDoubles->Append(aC.Z());
+
+ gp_Ax3 anAx3 = anInfo.Position();
+ gp_Dir aD = anAx3.Direction();
+ theDoubles->Append(aD.X());
+ theDoubles->Append(aD.Y());
+ theDoubles->Append(aD.Z());
+
+ theDoubles->Append(anInfo.Radius1());
+ theDoubles->Append(anInfo.Radius2());
+
+ gp_Pnt aP1 = anInfo.Pnt1();
+ theDoubles->Append(aP1.X());
+ theDoubles->Append(aP1.Y());
+ theDoubles->Append(aP1.Z());
+
+ gp_Pnt aP2 = anInfo.Pnt2();
+ theDoubles->Append(aP2.X());
+ theDoubles->Append(aP2.Y());
+ theDoubles->Append(aP2.Z());
+ }
+ break;
+ case GEOMAlgo_KN_LINE:
+ {
+ // ??? geompy.kind.LINE x1 y1 z1 x2 y2 z2
+ // (+) geompy.kind.LINE x1 y1 z1 dx dy dz
+ aKind = SK_LINE;
+
+ gp_Pnt aO = anInfo.Location();
+ theDoubles->Append(aO.X());
+ theDoubles->Append(aO.Y());
+ theDoubles->Append(aO.Z());
+
+ gp_Dir aD = anInfo.Direction();
+ theDoubles->Append(aD.X());
+ theDoubles->Append(aD.Y());
+ theDoubles->Append(aD.Z());
+ }
+ break;
+ case GEOMAlgo_KN_SEGMENT:
+ {
+ // (+) geompy.kind.SEGMENT x1 y1 z1 x2 y2 z2
+ aKind = SK_SEGMENT;
+
+ gp_Pnt aP1 = anInfo.Pnt1();
+ theDoubles->Append(aP1.X());
+ theDoubles->Append(aP1.Y());
+ theDoubles->Append(aP1.Z());
+
+ gp_Pnt aP2 = anInfo.Pnt2();
+ theDoubles->Append(aP2.X());
+ theDoubles->Append(aP2.Y());
+ theDoubles->Append(aP2.Z());
+ }
+ break;
+ default:
+ // ??? geompy.kind.EDGE nb_vertices _curve_type_id_
+ // (+) geompy.kind.EDGE nb_vertices
+ theIntegers->Append(anInfo.NbSubShapes(TopAbs_VERTEX));
+ }
+ }
+ break;
+
+ case TopAbs_VERTEX:
+ {
+ // (+) geompy.kind.VERTEX x y z
+ aKind = SK_VERTEX;
+
+ gp_Pnt aP = anInfo.Location();
+ theDoubles->Append(aP.X());
+ theDoubles->Append(aP.Y());
+ theDoubles->Append(aP.Z());
+ }
+ break;
+ }
+
+ SetErrorCode(OK);
+ return aKind;
+}
+
+//=============================================================================
+/*! Get LCS, corresponding to the given shape.
+ * Origin of the LCS is situated at the shape's center of mass.
+ * Axes of the LCS are obtained from shape's location or,
+ * if the shape is a planar face, from position of its plane.
+ */
+//=============================================================================
+gp_Ax3 GEOMImpl_IMeasureOperations::GetPosition (const TopoDS_Shape& theShape)
+{
+ gp_Ax3 aResult;
+
+ if (theShape.IsNull())
+ return aResult;
+
+ // Axes
+ aResult.Transform(theShape.Location().Transformation());
+ if (theShape.ShapeType() == TopAbs_FACE) {
+ Handle(Geom_Surface) aGS = BRep_Tool::Surface(TopoDS::Face(theShape));
+ if (!aGS.IsNull() && aGS->IsKind(STANDARD_TYPE(Geom_Plane))) {
+ Handle(Geom_Plane) aGPlane = Handle(Geom_Plane)::DownCast(aGS);
+ gp_Pln aPln = aGPlane->Pln();
+ aResult = aPln.Position();
+ }
+ }
+
+ // Origin
+ gp_Pnt aPnt;
+ if (theShape.ShapeType() == TopAbs_VERTEX) {
+ aPnt = BRep_Tool::Pnt(TopoDS::Vertex(theShape));
+ }
+ else {
+ GProp_GProps aSystem;
+ if (theShape.ShapeType() == TopAbs_EDGE || theShape.ShapeType() == TopAbs_WIRE)
+ BRepGProp::LinearProperties(theShape, aSystem);
+ else if (theShape.ShapeType() == TopAbs_FACE || theShape.ShapeType() == TopAbs_SHELL)
+ BRepGProp::SurfaceProperties(theShape, aSystem);
+ else
+ BRepGProp::VolumeProperties(theShape, aSystem);
+
+ aPnt = aSystem.CentreOfMass();
+ }
+
+ aResult.SetLocation(aPnt);
+
+ return aResult;
+}
+
+//=============================================================================
+/*!
+ * GetPosition
+ */
+//=============================================================================
+void GEOMImpl_IMeasureOperations::GetPosition
+ (Handle(GEOM_Object) theShape,
+ Standard_Real& Ox, Standard_Real& Oy, Standard_Real& Oz,
+ Standard_Real& Zx, Standard_Real& Zy, Standard_Real& Zz,
+ Standard_Real& Xx, Standard_Real& Xy, Standard_Real& Xz)
+{
+ SetErrorCode(KO);
+
+ //Set default values: global CS
+ Ox = Oy = Oz = Zx = Zy = Xy = Xz = 0.;
+ Zz = Xx = 1.;
+
+ if (theShape.IsNull()) return;
+
+ Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
+ if (aRefShape.IsNull()) return;
+
+ TopoDS_Shape aShape = aRefShape->GetValue();
+ if (aShape.IsNull()) {
+ SetErrorCode("The Objects has NULL Shape");
+ return;
+ }
+
+ try {
+#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
+ OCC_CATCH_SIGNALS;
+#endif
+
+ gp_Ax3 anAx3 = GetPosition(aShape);
+
+ gp_Pnt anOri = anAx3.Location();
+ gp_Dir aDirZ = anAx3.Direction();
+ gp_Dir aDirX = anAx3.XDirection();
+
+ // Output values
+ anOri.Coord(Ox, Oy, Oz);
+ aDirZ.Coord(Zx, Zy, Zz);
+ aDirX.Coord(Xx, Xy, Xz);
+ }
+ catch (Standard_Failure) {
+ Handle(Standard_Failure) aFail = Standard_Failure::Caught();
+ SetErrorCode(aFail->GetMessageString());
+ return;
+ }
+
+ SetErrorCode(OK);
+}
//=============================================================================
/*!
//Compute the CentreOfMass value
try {
+#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
+ OCC_CATCH_SIGNALS;
+#endif
if (!GetSolver()->ComputeFunction(aFunction)) {
SetErrorCode("Measure driver failed to compute centre of mass");
return NULL;
return aCDG;
}
+//=============================================================================
+/*!
+ * GetNormal
+ */
+//=============================================================================
+Handle(GEOM_Object) GEOMImpl_IMeasureOperations::GetNormal
+ (Handle(GEOM_Object) theFace,
+ Handle(GEOM_Object) theOptionalPoint)
+{
+ SetErrorCode(KO);
+
+ if (theFace.IsNull()) return NULL;
+
+ //Add a new Normale object
+ Handle(GEOM_Object) aNorm = GetEngine()->AddObject(GetDocID(), GEOM_VECTOR);
+
+ //Add a new Normale function
+ Handle(GEOM_Function) aFunction =
+ aNorm->AddFunction(GEOMImpl_MeasureDriver::GetID(), VECTOR_FACE_NORMALE);
+ if (aFunction.IsNull()) return NULL;
+
+ //Check if the function is set correctly
+ if (aFunction->GetDriverGUID() != GEOMImpl_MeasureDriver::GetID()) return NULL;
+
+ GEOMImpl_IMeasure aCI (aFunction);
+
+ Handle(GEOM_Function) aFace = theFace->GetLastFunction();
+ if (aFace.IsNull()) return NULL;
+
+ aCI.SetBase(aFace);
+
+ if (!theOptionalPoint.IsNull()) {
+ Handle(GEOM_Function) anOptPnt = theOptionalPoint->GetLastFunction();
+ aCI.SetPoint(anOptPnt);
+ }
+
+ //Compute the Normale value
+ try {
+#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
+ OCC_CATCH_SIGNALS;
+#endif
+ if (!GetSolver()->ComputeFunction(aFunction)) {
+ SetErrorCode("Measure driver failed to compute normake of face");
+ return NULL;
+ }
+ }
+ catch (Standard_Failure) {
+ Handle(Standard_Failure) aFail = Standard_Failure::Caught();
+ SetErrorCode(aFail->GetMessageString());
+ return NULL;
+ }
+
+ //Make a Python command
+ GEOM::TPythonDump pd (aFunction);
+ pd << aNorm << " = geompy.GetNormal(" << theFace;
+ if (!theOptionalPoint.IsNull()) {
+ pd << ", " << theOptionalPoint;
+ }
+ pd << ")";
+
+ SetErrorCode(OK);
+ return aNorm;
+}
+
//=============================================================================
/*!
* GetBasicProperties
//Compute the parameters
GProp_GProps LProps, SProps;
try {
+#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
+ OCC_CATCH_SIGNALS;
+#endif
BRepGProp::LinearProperties(aShape, LProps);
theLength = LProps.Mass();
GProp_GProps System;
try {
+#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
+ OCC_CATCH_SIGNALS;
+#endif
if (aShape.ShapeType() == TopAbs_VERTEX ||
aShape.ShapeType() == TopAbs_EDGE ||
aShape.ShapeType() == TopAbs_WIRE) {
Bnd_Box B;
try {
+#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
+ OCC_CATCH_SIGNALS;
+#endif
BRepBndLib::Add(aShape, B);
B.Get(Xmin, Ymin, Zmin, Xmax, Ymax, Zmax);
}
FaceMax = EdgeMax = VertMax = -RealLast();
try {
+#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
+ OCC_CATCH_SIGNALS;
+#endif
for (TopExp_Explorer ExF (aShape, TopAbs_FACE); ExF.More(); ExF.Next()) {
TopoDS_Face Face = TopoDS::Face(ExF.Current());
T = BRep_Tool::Tolerance(Face);
*/
//=============================================================================
bool GEOMImpl_IMeasureOperations::CheckShape (Handle(GEOM_Object) theShape,
+ const Standard_Boolean theIsCheckGeom,
TCollection_AsciiString& theDump)
{
SetErrorCode(KO);
//Compute the parameters
bool isValid = false;
try {
- BRepCheck_Analyzer ana (aShape, false);
+#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
+ OCC_CATCH_SIGNALS;
+#endif
+ BRepCheck_Analyzer ana (aShape, theIsCheckGeom);
if (ana.IsValid()) {
theDump.Clear();
isValid = true;
Astr = Astr + " Number of sub-shapes : \n";
try {
+#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
+ OCC_CATCH_SIGNALS;
+#endif
int iType, nbTypes [TopAbs_SHAPE];
for (iType = 0; iType < TopAbs_SHAPE; ++iType)
nbTypes[iType] = 0;
//Compute the parameters
try {
+#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
+ OCC_CATCH_SIGNALS;
+#endif
BRepExtrema_DistShapeShape dst (aShape1, aShape2);
if (dst.IsDone()) {
gp_Pnt PMin1, PMin2, P1, P2;
}
//=======================================================================
-//function : PointCoordinates
-//purpose : Get coordinates of point
+/*!
+ * Get coordinates of point
+ */
//=======================================================================
-void GEOMImpl_IMeasureOperations::PointCoordinates( Handle(GEOM_Object) theShape,
- Standard_Real& theX, Standard_Real& theY, Standard_Real& theZ )
+void GEOMImpl_IMeasureOperations::PointCoordinates (Handle(GEOM_Object) theShape,
+ Standard_Real& theX, Standard_Real& theY, Standard_Real& theZ)
{
- SetErrorCode( KO );
+ SetErrorCode(KO);
- if ( theShape.IsNull() )
+ if (theShape.IsNull())
return;
Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
- if ( aRefShape.IsNull() )
+ if (aRefShape.IsNull())
return;
TopoDS_Shape aShape = aRefShape->GetValue();
- if ( aShape.IsNull() || aShape.ShapeType() != TopAbs_VERTEX )
+ if (aShape.IsNull() || aShape.ShapeType() != TopAbs_VERTEX)
{
SetErrorCode( "Shape must be a vertex" );
return;
}
- try
- {
+ try {
+#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
+ OCC_CATCH_SIGNALS;
+#endif
gp_Pnt aPnt = BRep_Tool::Pnt( TopoDS::Vertex( aShape ) );
theX = aPnt.X();
theY = aPnt.Y();
theZ = aPnt.Z();
- SetErrorCode( OK );
+
+ SetErrorCode(OK);
}
- catch ( Standard_Failure )
+ catch (Standard_Failure)
{
Handle(Standard_Failure) aFail = Standard_Failure::Caught();
SetErrorCode( aFail->GetMessageString() );
}
}
+//=======================================================================
+/*!
+ * Compute angle (in degrees) between two lines
+ */
+//=======================================================================
+Standard_Real GEOMImpl_IMeasureOperations::GetAngle (Handle(GEOM_Object) theLine1,
+ Handle(GEOM_Object) theLine2)
+{
+ SetErrorCode(KO);
+
+ Standard_Real anAngle = -1.0;
+
+ if (theLine1.IsNull() || theLine2.IsNull())
+ return anAngle;
+
+ Handle(GEOM_Function) aRefLine1 = theLine1->GetLastFunction();
+ Handle(GEOM_Function) aRefLine2 = theLine2->GetLastFunction();
+ if (aRefLine1.IsNull() || aRefLine2.IsNull())
+ return anAngle;
+
+ TopoDS_Shape aLine1 = aRefLine1->GetValue();
+ TopoDS_Shape aLine2 = aRefLine2->GetValue();
+ if (aLine1.IsNull() || aLine2.IsNull() ||
+ aLine1.ShapeType() != TopAbs_EDGE ||
+ aLine2.ShapeType() != TopAbs_EDGE)
+ {
+ SetErrorCode("Two edges must be given");
+ return anAngle;
+ }
+
+ try {
+#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
+ OCC_CATCH_SIGNALS;
+#endif
+ TopoDS_Edge E1 = TopoDS::Edge(aLine1);
+ TopoDS_Edge E2 = TopoDS::Edge(aLine2);
+
+ double fp,lp;
+ Handle(Geom_Curve) C1 = BRep_Tool::Curve(E1,fp,lp);
+ Handle(Geom_Curve) C2 = BRep_Tool::Curve(E2,fp,lp);
+
+ if (!C1->IsKind(STANDARD_TYPE(Geom_Line)) ||
+ !C2->IsKind(STANDARD_TYPE(Geom_Line)))
+ {
+ SetErrorCode("The edges must be linear");
+ return anAngle;
+ }
+
+ Handle(Geom_Line) L1 = Handle(Geom_Line)::DownCast(C1);
+ Handle(Geom_Line) L2 = Handle(Geom_Line)::DownCast(C2);
+
+ gp_Lin aLin1 = L1->Lin();
+ gp_Lin aLin2 = L2->Lin();
+
+ anAngle = aLin1.Angle(aLin2);
+ anAngle /= PI180; // convert radians into degrees
+
+ SetErrorCode(OK);
+ }
+ catch (Standard_Failure)
+ {
+ Handle(Standard_Failure) aFail = Standard_Failure::Caught();
+ SetErrorCode(aFail->GetMessageString());
+ }
+
+ return anAngle;
+}
+
//=======================================================================
//function : StructuralDump
//purpose : Structural (data exchange) style of output.