diff --git a/doc/salome/examples/transformation_operations_ex07.py b/doc/salome/examples/transformation_operations_ex07.py index f76bd9036..d323cf0b7 100644 --- a/doc/salome/examples/transformation_operations_ex07.py +++ b/doc/salome/examples/transformation_operations_ex07.py @@ -38,3 +38,19 @@ prj = geompy.MakeProjection(v1, w1) geompy.addToStudy(w1, "w1") geompy.addToStudy(v1, "v1") geompy.addToStudy(prj, "projOnWire") + +#projection of a wire on cylinder +pp1 = geompy.MakeVertex(100, 200, 0) +pp2 = geompy.MakeVertex(100, 200, 80) +pp3 = geompy.MakeVertex(100, 220, 90) +pp4 = geompy.MakeVertex(100, 130, 80) +pp5 = geompy.MakeVertex(100, 90, 80) +cc1 = geompy.MakeInterpol([pp1, pp2, pp3, pp4, pp5], True, False) +ww1 = geompy.MakeWire([cc1], 1.e-7) +vx = geompy.MakeVectorDXDYDZ(100, 0, 0) +pln1 = geompy.MakePlane(pp1, vx, 200) +face1 = geompy.MakeFaceFromSurface(pln1, ww1) +prj_cyl = geompy.MakeProjectionOnCylinder(face1, 100) + +geompy.addToStudy(face1, "pln_face") +geompy.addToStudy(prj_cyl, "projOnCylinder") diff --git a/doc/salome/gui/GEOM/images/proj_on_cyl_dlg.png b/doc/salome/gui/GEOM/images/proj_on_cyl_dlg.png new file mode 100644 index 000000000..38d81b51e Binary files /dev/null and b/doc/salome/gui/GEOM/images/proj_on_cyl_dlg.png differ diff --git a/doc/salome/gui/GEOM/images/proj_on_cyl_preview.png b/doc/salome/gui/GEOM/images/proj_on_cyl_preview.png new file mode 100644 index 000000000..85d767eab Binary files /dev/null and b/doc/salome/gui/GEOM/images/proj_on_cyl_preview.png differ diff --git a/doc/salome/gui/GEOM/input/projection_on_cylinder_operation.doc b/doc/salome/gui/GEOM/input/projection_on_cylinder_operation.doc new file mode 100644 index 000000000..be0c5aa27 --- /dev/null +++ b/doc/salome/gui/GEOM/input/projection_on_cylinder_operation.doc @@ -0,0 +1,40 @@ +/*! + +\page projection_on_cylinder_operation_page Projection on Cylinder + +\n To produce a Projection on Cylinder in the Main Menu select +Operations - > Transformation - > Projection on Cylinder + +\n This operation makes a projection of a Source planar wire or face on +a cylinder defined by its radius. The cylinder's coordinate system is +the same as the global coordinate system. The result represents a wire or +a face that represents a projection of the source shape onto a cylinder. + +To make a projection it is necessary to define: +- \b Object to be projected. It can be either a planar wire or a face; +- \b Radius of the cylinder; +- Starting angle from the cylinder's X axis around Z axis. This is +the angle of the projection starting. +- Length angle in which to project the total length of +the wire. If it is unchecked the projection is not scaled and natural +wire length is kept for the projection. + +\ref restore_presentation_parameters_page "Advanced options". + +\image html proj_on_cyl_dlg.png + +\n Example: + +\image html proj_on_cyl_preview.png "The curve (in red) and its projection on the cylinder" + +\n TUI Command: geompy.MakeProjectionOnCylinder(theObject, theRadius, +theStartAngle=0.0, theAngleLength=-1.0), +where \em theObject is a shape which has to be projected, \em theRadius +is a cylinder radius, \em theStartAngle the starting angle of projection in +radians, \em theAngleLength the projection length angle in radians. +The \em Result will be a \em GEOM_Object. + +Our TUI Scripts provide you with useful examples of the use of +\ref tui_projection "Transformation Operations". + +*/ diff --git a/doc/salome/gui/GEOM/input/transformation_operations.doc b/doc/salome/gui/GEOM/input/transformation_operations.doc index ac745b669..6ce6395ce 100644 --- a/doc/salome/gui/GEOM/input/transformation_operations.doc +++ b/doc/salome/gui/GEOM/input/transformation_operations.doc @@ -17,6 +17,7 @@ which allow to:
  • Create an \subpage offset_operation_page "Offset" of an object.
  • Create a \subpage projection_operation_page "Projection" of an object on a face.
  • Create an \subpage extension_operation_page "Extension" of an edge or a face.
  • +
  • Create a \subpage projection_on_cylinder_operation_page "Projection on cylinder".
  • Create a simultaneous \subpage multi_translation_operation_page "Translation in several directions".
  • Create a simultaneous \subpage multi_rotation_operation_page
  • "Rotation in several directions". diff --git a/doc/salome/gui/GEOM/input/tui_test_all.doc b/doc/salome/gui/GEOM/input/tui_test_all.doc index b1f915ea2..f2407ca29 100644 --- a/doc/salome/gui/GEOM/input/tui_test_all.doc +++ b/doc/salome/gui/GEOM/input/tui_test_all.doc @@ -61,7 +61,7 @@ \until Scale4 \anchor swig_all_trsf_more -\until MakeProjectionOnWire +\until MakeProjectionOnCylinder \anchor swig_ChangeOrientation \until ChangeOrientation diff --git a/idl/GEOM_Gen.idl b/idl/GEOM_Gen.idl index 9bdfda2b2..eaea44370 100644 --- a/idl/GEOM_Gen.idl +++ b/idl/GEOM_Gen.idl @@ -1420,6 +1420,31 @@ module GEOM * \return theObject. */ GEOM_Object RecomputeObject (in GEOM_Object theObject); + + /*! + * \brief Compute the projection of a wire or a face on a cylinder. + * + * This method computes a wire or a face or a compound of faces + * that represents a projection of the source shape onto cylinder. + * The cylinder's coordinate system is the same as the global coordinate + * system. + * + * \param theObject The object to be projected. It can be either + * a planar wire or a face. + * \param theRadius The radius of the cylinder. + * \param theStartAngle The starting angle from the cylinder's X axis + * around Z axis. The angle from which the projection is started. + * \param theAngleLength The projection length angle. The angle in which + * to project the total length of the wire. If it is negative the + * projection is not scaled and natural wire length is kept for + * the projection. + * \return A wire or a face or a compound of faces that represents a + * projection of the source shape onto a cylinder. + */ + GEOM_Object MakeProjectionOnCylinder (in GEOM_Object theObject, + in double theRadius, + in double theStartAngle, + in double theAngleLength); }; /*! diff --git a/resources/CMakeLists.txt b/resources/CMakeLists.txt index 3a1bb3200..cef2c42f2 100755 --- a/resources/CMakeLists.txt +++ b/resources/CMakeLists.txt @@ -134,6 +134,7 @@ SET( _res_files projection.png projection_on_edge.png projection_on_wire.png + proj_on_cyl.png origin_and_vectors.png partition.png partitionkeep.png diff --git a/resources/proj_on_cyl.png b/resources/proj_on_cyl.png new file mode 100644 index 000000000..bd52b7188 Binary files /dev/null and b/resources/proj_on_cyl.png differ diff --git a/src/GEOMGUI/GEOM_images.ts b/src/GEOMGUI/GEOM_images.ts index 489aaa5aa..1e906fe81 100644 --- a/src/GEOMGUI/GEOM_images.ts +++ b/src/GEOMGUI/GEOM_images.ts @@ -463,6 +463,10 @@ ICON_DLG_EXTEND_FACE faceextension.png + + ICO_DLG_PROJ_ON_CYL + proj_on_cyl.png + ICON_DLG_PARTITION partition.png @@ -1155,6 +1159,10 @@ ICO_EXTENSION edgeextension.png + + ICO_PROJ_ON_CYL + proj_on_cyl.png + ICO_ORIGIN_AND_VECTORS origin_and_vectors.png diff --git a/src/GEOMGUI/GEOM_msg_en.ts b/src/GEOMGUI/GEOM_msg_en.ts index 4da50d2e7..5142eb365 100644 --- a/src/GEOMGUI/GEOM_msg_en.ts +++ b/src/GEOMGUI/GEOM_msg_en.ts @@ -1260,6 +1260,10 @@ Please, select face, shell or solid and try again GEOM_PROJECTION_TITLE Projection + + GEOM_PROJECTION_NAME + Projection + GEOM_PROJ_ON_FACE_SOURCE Source vertex, edge or wire @@ -2844,6 +2848,10 @@ Please, select face, shell or solid and try again MEN_PROJECTION Projection + + MEN_PROJ_ON_CYL + Projection on Cylinder + MEN_OPERATIONS Operations @@ -3804,6 +3812,10 @@ Please, select face, shell or solid and try again STB_PROJECTION Project a point, an edge or a wire on a face + + STB_PROJ_ON_CYL + Project a wire or a face on a cylinder + STB_ORIGIN_AND_VECTORS Create an origin and base Vectors @@ -4424,6 +4436,10 @@ Please, select face, shell or solid and try again TOP_PROJECTION Projection + + TOP_PROJ_ON_CYL + Projection on Cylinder + TOP_ORIGIN_AND_VECTORS Create an origin and base Vectors @@ -7404,4 +7420,19 @@ Do you want to create new material? Materials: %1 of %2 + + TransformationGUI_ProjectionOnCylDlg + + GEOM_PROJ_ON_CYL_TITLE + Projection On A Cylinder + + + GEOM_PROJ_ON_CYL_START_ANGLE + Starting angle + + + GEOM_PROJ_ON_CYL_LENGTH_ANGLE + Length angle + + diff --git a/src/GEOMGUI/GeometryGUI.cxx b/src/GEOMGUI/GeometryGUI.cxx index 143f63b05..3e90cd95a 100644 --- a/src/GEOMGUI/GeometryGUI.cxx +++ b/src/GEOMGUI/GeometryGUI.cxx @@ -587,6 +587,7 @@ void GeometryGUI::OnGUIEvent( int id, const QVariant& theParam ) case GEOMOp::OpScale: // MENU TRANSFORMATION - SCALE case GEOMOp::OpOffset: // MENU TRANSFORMATION - OFFSET case GEOMOp::OpProjection: // MENU TRANSFORMATION - PROJECTION + case GEOMOp::OpProjOnCyl: // MENU TRANSFORMATION - PROJECTION ON CYLINDER case GEOMOp::OpMultiTranslate: // MENU TRANSFORMATION - MULTI-TRANSLATION case GEOMOp::OpMultiRotate: // MENU TRANSFORMATION - MULTI-ROTATION case GEOMOp::OpReimport: // CONTEXT(POPUP) MENU - RELOAD_IMPORTED @@ -966,6 +967,7 @@ void GeometryGUI::initialize( CAM_Application* app ) createGeomAction( GEOMOp::OpScale, "SCALE" ); createGeomAction( GEOMOp::OpOffset, "OFFSET" ); createGeomAction( GEOMOp::OpProjection, "PROJECTION" ); + createGeomAction( GEOMOp::OpProjOnCyl, "PROJ_ON_CYL" ); createGeomAction( GEOMOp::OpMultiTranslate, "MUL_TRANSLATION" ); createGeomAction( GEOMOp::OpMultiRotate, "MUL_ROTATION" ); createGeomAction( GEOMOp::OpExtension, "EXTENSION" ); @@ -1211,6 +1213,7 @@ void GeometryGUI::initialize( CAM_Application* app ) createMenu( GEOMOp::OpOffset, transId, -1 ); createMenu( GEOMOp::OpProjection, transId, -1 ); createMenu( GEOMOp::OpExtension, transId, -1 ); + createMenu( GEOMOp::OpProjOnCyl, transId, -1 ); createMenu( separator(), transId, -1 ); createMenu( GEOMOp::OpMultiTranslate, transId, -1 ); createMenu( GEOMOp::OpMultiRotate, transId, -1 ); @@ -1386,6 +1389,7 @@ void GeometryGUI::initialize( CAM_Application* app ) createTool( GEOMOp::OpOffset, transTbId ); createTool( GEOMOp::OpProjection, transTbId ); createTool( GEOMOp::OpExtension, transTbId ); + createTool( GEOMOp::OpProjOnCyl, transTbId ); createTool( separator(), transTbId ); createTool( GEOMOp::OpMultiTranslate, transTbId ); createTool( GEOMOp::OpMultiRotate, transTbId ); diff --git a/src/GEOMGUI/GeometryGUI_Operations.h b/src/GEOMGUI/GeometryGUI_Operations.h index 2acdd53f4..915f5d1f1 100644 --- a/src/GEOMGUI/GeometryGUI_Operations.h +++ b/src/GEOMGUI/GeometryGUI_Operations.h @@ -148,6 +148,7 @@ namespace GEOMOp { OpReimport = 3608, // POPUP MENU - RELOAD IMPORTED OpProjection = 3609, // MENU OPERATIONS - TRANSFORMATION - PROJECTION OpExtension = 3610, // MENU OPERATIONS - TRANSFORMATION - EXTENSION + OpProjOnCyl = 3611, // MENU OPERATIONS - TRANSFORMATION - PROJECTION ON CYLINDER // OperationGUI ----------------//-------------------------------- OpPartition = 3700, // MENU OPERATION - PARTITION OpArchimede = 3701, // MENU OPERATION - ARCHIMEDE diff --git a/src/GEOMImpl/CMakeLists.txt b/src/GEOMImpl/CMakeLists.txt index 5cc90b4ed..5c59b2e72 100755 --- a/src/GEOMImpl/CMakeLists.txt +++ b/src/GEOMImpl/CMakeLists.txt @@ -97,6 +97,7 @@ SET(GEOMImpl_HEADERS GEOMImpl_ITranslate.hxx GEOMImpl_IMirror.hxx GEOMImpl_IProjection.hxx + GEOMImpl_IProjOnCyl.hxx GEOMImpl_IOffset.hxx GEOMImpl_IScale.hxx GEOMImpl_IRotate.hxx diff --git a/src/GEOMImpl/GEOMImpl_IProjOnCyl.hxx b/src/GEOMImpl/GEOMImpl_IProjOnCyl.hxx new file mode 100644 index 000000000..9fc6024d1 --- /dev/null +++ b/src/GEOMImpl/GEOMImpl_IProjOnCyl.hxx @@ -0,0 +1,61 @@ +// Copyright (C) 2007-2014 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 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 +// version 2.1 of the License, or (at your option) any later version. +// +// 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 +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +//NOTE: This is an interface to a function for the Projection on cylinder creation. + +#include "GEOM_Function.hxx" + +#define PROJECTION_ARG_SHAPE 1 +#define PROJECTION_ARG_RADIUS 2 +#define PROJECTION_ARG_START_ANGLE 3 +#define PROJECTION_ARG_ANGLE_LENGTH 4 + +class GEOMImpl_IProjOnCyl +{ + +public: + + GEOMImpl_IProjOnCyl(Handle(GEOM_Function) theFunction): _func(theFunction) {} + + void SetShape (const Handle(GEOM_Function) &theShape) + { _func->SetReference(PROJECTION_ARG_SHAPE, theShape); } + void SetRadius (const Standard_Real theRadius) + { _func->SetReal(PROJECTION_ARG_RADIUS, theRadius); } + void SetStartAngle (const Standard_Real theStartAngle) + { _func->SetReal(PROJECTION_ARG_START_ANGLE, theStartAngle); } + void SetAngleLength (const Standard_Real theAngleLength) + { _func->SetReal(PROJECTION_ARG_ANGLE_LENGTH, theAngleLength); } + + Handle(GEOM_Function) GetShape() + { return _func->GetReference(PROJECTION_ARG_SHAPE); } + Standard_Real GetRadius() + { return _func->GetReal(PROJECTION_ARG_RADIUS ); } + Standard_Real GetStartAngle() + { return _func->GetReal(PROJECTION_ARG_START_ANGLE ); } + Standard_Real GetAngleLength() + { return _func->GetReal(PROJECTION_ARG_ANGLE_LENGTH ); } + + private: + + Handle(GEOM_Function) _func; + +}; diff --git a/src/GEOMImpl/GEOMImpl_ITransformOperations.cxx b/src/GEOMImpl/GEOMImpl_ITransformOperations.cxx index 766531fdb..5d89b0c0a 100644 --- a/src/GEOMImpl/GEOMImpl_ITransformOperations.cxx +++ b/src/GEOMImpl/GEOMImpl_ITransformOperations.cxx @@ -35,6 +35,7 @@ #include #include #include +#include #include #include #include @@ -2267,3 +2268,78 @@ Handle(GEOM_Object) GEOMImpl_ITransformOperations::TransformLikeOtherCopy SetErrorCode(OK); return aCopy; } + +//============================================================================= +/*! + * MakeProjectionOnCylinder + */ +//============================================================================= +Handle(GEOM_Object) GEOMImpl_ITransformOperations::MakeProjectionOnCylinder + (const Handle(GEOM_Object) &theObject, + const Standard_Real theRadius, + const Standard_Real theStartAngle, + const Standard_Real theAngleLength) +{ + SetErrorCode(KO); + + if (theObject.IsNull()) { + return NULL; + } + + Handle(GEOM_Function) aLastFunction = theObject->GetLastFunction(); + + if (aLastFunction.IsNull()) { + //There is no function which creates an object to be projected + return NULL; + } + + //Add a new Projection object + Handle(GEOM_Object) aResult = + GetEngine()->AddObject(GetDocID(), GEOM_PROJECTION); + + //Add a Projection function + Handle(GEOM_Function) aFunction = aResult->AddFunction + (GEOMImpl_ProjectionDriver::GetID(), PROJECTION_ON_CYLINDER); + + //Check if the function is set correctly + if (aFunction->GetDriverGUID() != GEOMImpl_ProjectionDriver::GetID()) { + return aResult; + } + + GEOMImpl_IProjOnCyl aProj (aFunction); + + aProj.SetShape(aLastFunction); + aProj.SetRadius(theRadius); + aProj.SetStartAngle(theStartAngle); + aProj.SetAngleLength(theAngleLength); + + //Compute the Projection + try { + OCC_CATCH_SIGNALS; + if (!GetSolver()->ComputeFunction(aFunction)) { + SetErrorCode("Projection driver failed"); + return aResult; + } + } + catch (Standard_Failure) { + Handle(Standard_Failure) aFail = Standard_Failure::Caught(); + SetErrorCode(aFail->GetMessageString()); + return aResult; + } + + //Make a Python command + GEOM::TPythonDump pd(aFunction); + + pd << aResult << " = geompy.MakeProjectionOnCylinder(" + << theObject << ", " << theRadius << ", " << theStartAngle; + + if (theAngleLength >= 0.) { + pd << ", " << theAngleLength; + } + + pd << ")"; + + SetErrorCode(OK); + + return aResult; +} diff --git a/src/GEOMImpl/GEOMImpl_ITransformOperations.hxx b/src/GEOMImpl/GEOMImpl_ITransformOperations.hxx index 2c44b3854..155dbfdd9 100644 --- a/src/GEOMImpl/GEOMImpl_ITransformOperations.hxx +++ b/src/GEOMImpl/GEOMImpl_ITransformOperations.hxx @@ -191,6 +191,12 @@ class GEOMImpl_ITransformOperations : public GEOM_IOperations Standard_EXPORT Handle(GEOM_Object) TransformLikeOtherCopy (Handle(GEOM_Object) theObject, Handle(GEOM_Object) theSample); + Standard_EXPORT Handle(GEOM_Object) MakeProjectionOnCylinder + (const Handle(GEOM_Object) &theObject, + const Standard_Real theRadius, + const Standard_Real theStartAngle, + const Standard_Real theAngleLength); + }; #endif diff --git a/src/GEOMImpl/GEOMImpl_ProjectionDriver.cxx b/src/GEOMImpl/GEOMImpl_ProjectionDriver.cxx index 064dbb91b..d226969c8 100644 --- a/src/GEOMImpl/GEOMImpl_ProjectionDriver.cxx +++ b/src/GEOMImpl/GEOMImpl_ProjectionDriver.cxx @@ -26,16 +26,26 @@ #include #include +#include #include #include +#include +#include +#include #include +#include #include +#include +#include #include +#include #include #include +#include #include #include +#include #include #include @@ -44,11 +54,14 @@ #include #include #include -#include +#include +#include #include #include +#include #include +#include #include #include @@ -400,6 +413,42 @@ Standard_Integer GEOMImpl_ProjectionDriver::Execute(TFunction_Logbook& log) cons if (!hasValidSolution) { Standard_ConstructionError::Raise("Projection aborted : no projection"); } + } else if (aType == PROJECTION_ON_CYLINDER) { + GEOMImpl_IProjOnCyl aProj (aFunction); + Handle(GEOM_Function) aShapeFunction = aProj.GetShape(); + + if (aShapeFunction.IsNull()) { + return 0; + } + + TopoDS_Shape aShape = aShapeFunction->GetValue(); + + if (aShape.IsNull()) { + return 0; + } + + // Get the face. + const TopAbs_ShapeEnum aType = aShape.ShapeType(); + const Standard_Real aRadius = aProj.GetRadius(); + const Standard_Real aStartAngle = aProj.GetStartAngle(); + const Standard_Real aLengthAngle = aProj.GetAngleLength(); + + if (aType != TopAbs_WIRE && aType != TopAbs_FACE) { + return 0; + } + + if (aRadius <= Precision::Confusion()) { + return 0; + } + + TopoDS_Shape aProjShape = + projectOnCylinder(aShape, aRadius, aStartAngle, aLengthAngle); + + if (aProjShape.IsNull()) { + return 0; + } + + aFunction->SetValue(aProjShape); } return 1; @@ -438,6 +487,21 @@ GetCreationInformation(std::string& theOperationName, AddParam(theParams, "Point", aProj.GetPoint()); AddParam(theParams, "Shape", aProj.GetShape()); + break; + } + case PROJECTION_ON_CYLINDER: + { + GEOMImpl_IProjOnCyl aProj (function); + const Standard_Real aLengthAngle = aProj.GetAngleLength(); + + AddParam(theParams, "Shape", aProj.GetShape()); + AddParam(theParams, "Radius", aProj.GetRadius()); + AddParam(theParams, "Start angle", aProj.GetStartAngle()); + + if (aLengthAngle >= 0.) { + AddParam(theParams, "Length angle", aLengthAngle); + } + break; } default: @@ -447,5 +511,242 @@ GetCreationInformation(std::string& theOperationName, return true; } +//================================================================================ +/*! + * \brief Performs projection of a planar wire or a face on a cylinder. + */ +//================================================================================ + +TopoDS_Shape GEOMImpl_ProjectionDriver::projectOnCylinder + (const TopoDS_Shape &theShape, + const Standard_Real theRadius, + const Standard_Real theStartAngle, + const Standard_Real theAngleLength) const +{ + TopoDS_Shape aResult; + + // Get the face. + const TopAbs_ShapeEnum aType = theShape.ShapeType(); + TopoDS_Face aFace; + + if (aType == TopAbs_WIRE) { + // Try to create a planar face. + TopoDS_Wire aWire = TopoDS::Wire(theShape); + BRepBuilderAPI_MakeFace aMkFace(aWire, Standard_True); + + if (aMkFace.IsDone()) { + aFace = aMkFace.Face(); + } else { + // Check if the wire is a straight line. + TopExp_Explorer anEExp(aWire, TopAbs_EDGE); + TopoDS_Edge anEdge; + + for (; anEExp.More(); anEExp.Next()) { + anEdge = TopoDS::Edge(anEExp.Current()); + + if (!BRep_Tool::Degenerated(anEdge)) { + break; + } + } + + if (anEExp.More()) { + // Not degenerated edge found. Try to create a plane. + Standard_Real aPar[2]; + Handle(Geom_Curve) aCurve = BRep_Tool::Curve(anEdge, aPar[0], aPar[1]); + gp_Pnt aP0 = aCurve->Value(aPar[0]); + gp_Pnt aP1 = aCurve->Value(0.5*(aPar[1] + aPar[0])); + gp_Vec aX(aP1.XYZ().Subtracted(aP0.XYZ())); + Standard_Real aTolConf = Precision::Confusion(); + + if (aX.Magnitude() > aTolConf) { + aX.Normalize(); + + // Get the plane normal ortogonal to Z axis. + gp_Vec aZ(0., 0., 1.); + gp_Vec aN = aX.Crossed(aZ); + + if (aN.Magnitude() <= aTolConf) { + // aX is parallel to aZ. Get the plane normal ortogonal to Y axis. + gp_Vec aY(0., 1., 0.); + + aN = aX.Crossed(aY); + } + + if (aN.Magnitude() > aTolConf) { + gp_Ax3 anAxis(aP0, gp_Dir(aN), gp_Dir(aX)); + Handle(Geom_Plane) aPlane = new Geom_Plane(anAxis); + BRepBuilderAPI_MakeFace aMkFace(aPlane, aWire); + + if (aMkFace.IsDone()) { + aFace = aMkFace.Face(); + } + } + } + } + } + } else if (aType == TopAbs_FACE) { + aFace = TopoDS::Face(theShape); + } + + if (aFace.IsNull()) { + return aResult; + } + + // Compute 2d translation transformation. + TopoDS_Wire anOuterWire = BRepTools::OuterWire(aFace); + Standard_Real aU[2]; + Standard_Real aV[2]; + BRepTools_WireExplorer aOWExp(anOuterWire, aFace); + + if (!aOWExp.More()) { + // NEVERREACHED + return aResult; + } + + // Compute anisotropic transformation from a face's 2d space + // to cylinder's 2d space. + BRepTools::UVBounds(aFace, anOuterWire, aU[0], aU[1], aV[0], aV[1]); + + TopoDS_Vertex aFirstVertex = aOWExp.CurrentVertex(); + TopoDS_Edge aFirstEdge = aOWExp.Current(); + gp_Pnt aPnt = BRep_Tool::Pnt(aFirstVertex); + BRepAdaptor_Curve2d anAdaptorCurve(aFirstEdge, aFace); + Standard_Real aParam = + BRep_Tool::Parameter(aFirstVertex, aFirstEdge, aFace); + gp_Pnt2d aPntUV = anAdaptorCurve.Value(aParam); + + GEOMUtils::Trsf2d aTrsf2d + (1./theRadius, 0., theStartAngle - aU[0]/theRadius, + 0., 1., aPnt.Z() - 0.5*(aV[1] - aV[0]) - aPntUV.Y()); + + // Compute scaling trsf. + const Standard_Boolean isToScale = theAngleLength >= Precision::Angular(); + gp_Trsf2d aScaleTrsf; + + if (isToScale) { + // Perform 2d scaling. + gp_Pnt2d aMidPnt(0.5*(aU[1] + aU[0]), 0.5*(aV[1] + aV[0])); + const Standard_Real aScaleFactor = theAngleLength*theRadius/(aU[1] - aU[0]); + + aTrsf2d.TransformD0(aMidPnt); + + aScaleTrsf.SetScale(aMidPnt, aScaleFactor); + } + + // Get 2d presentation of a face. + Handle(Geom_Surface) aCylinder = + new Geom_CylindricalSurface(gp_Ax3(), theRadius); + GeomAdaptor_Surface aGACyl(aCylinder); + TopExp_Explorer anExp(aFace, TopAbs_WIRE); + Standard_Real aPar[2]; + TopTools_ListOfShape aWires; + Standard_Real aUResol = aGACyl.UResolution(Precision::Confusion()); + Standard_Real aVResol = aGACyl.VResolution(Precision::Confusion()); + + for (; anExp.More(); anExp.Next()) { + TopoDS_Wire aWire = TopoDS::Wire(anExp.Current()); + BRepTools_WireExplorer aWExp(aWire, aFace); + BRepBuilderAPI_MakeWire aMkWire; + + for (; aWExp.More(); aWExp.Next()) { + TopoDS_Edge anEdge = aWExp.Current(); + Handle(Geom2d_Curve) aCurve = + BRep_Tool::CurveOnSurface(anEdge, aFace, aPar[0], aPar[1]); + + if (aCurve.IsNull()) { + continue; + } + + // Transform the curve to cylinder's parametric space. + GEOMUtils::Handle(HTrsfCurve2d) aTrsfCurve = + new GEOMUtils::HTrsfCurve2d(aCurve, aPar[0], aPar[1], aTrsf2d); + Approx_Curve2d aConv (aTrsfCurve, aPar[0], aPar[1], + aUResol, aVResol, GeomAbs_C1, + 9, 1000); + + if (!aConv.IsDone() && !aConv.HasResult()) { + return aResult; + } + + Handle(Geom2d_Curve) aCylCurve = aConv.Curve(); + + if (isToScale) { + aCylCurve->Transform(aScaleTrsf); + } + + // Create edge and add it to the wire. + BRepBuilderAPI_MakeEdge aMkEdge(aCylCurve, aCylinder); + + if (!aMkEdge.IsDone()) { + return aResult; + } + + aMkWire.Add(aMkEdge.Edge()); + + if (!aMkWire.IsDone()) { + return aResult; + } + } + + if (aWire.IsSame(anOuterWire)) { + // Make the outer wire first. + aWires.Prepend(aMkWire.Wire()); + } else { + aWires.Append(aMkWire.Wire()); + } + } + + // Create a face. + if (aWires.IsEmpty()) { + return aResult; + } + + TopTools_ListIteratorOfListOfShape aWIter(aWires); + TopoDS_Wire aWire = TopoDS::Wire(aWIter.Value()); + BRepBuilderAPI_MakeFace aMkFace(aCylinder, aWire); + + if (!aMkFace.IsDone()) { + return aResult; + } + + for (aWIter.Next(); aWIter.More(); aWIter.Next()) { + aWire = TopoDS::Wire(aWIter.Value()); + aMkFace.Add(aWire); + + if (!aMkFace.IsDone()) { + return aResult; + } + } + + // Build 3D curves. + TopoDS_Face aCylFace = aMkFace.Face(); + TopoDS_Shape aResShape; + + BRepLib::BuildCurves3d(aCylFace); + + // Check shape. + if (aType == TopAbs_WIRE) { + TopExp_Explorer aResExp(aCylFace, TopAbs_WIRE); + + if (aResExp.More()) { + aResShape = aResExp.Current(); + } + } else { + aResShape = aCylFace; + } + + if (aResShape.IsNull() == Standard_False) { + if (!GEOMUtils::CheckShape(aResShape, true)) { + if (!GEOMUtils::FixShapeTolerance(aResShape)) { + return aResult; + } + } + + aResult = aResShape; + } + + return aResult; +} + IMPLEMENT_STANDARD_HANDLE (GEOMImpl_ProjectionDriver,GEOM_BaseDriver); IMPLEMENT_STANDARD_RTTIEXT (GEOMImpl_ProjectionDriver,GEOM_BaseDriver); diff --git a/src/GEOMImpl/GEOMImpl_ProjectionDriver.hxx b/src/GEOMImpl/GEOMImpl_ProjectionDriver.hxx index 5766c2392..ee703af55 100644 --- a/src/GEOMImpl/GEOMImpl_ProjectionDriver.hxx +++ b/src/GEOMImpl/GEOMImpl_ProjectionDriver.hxx @@ -58,6 +58,7 @@ #endif class TColStd_SequenceOfExtendedString; +class TopoDS_Shape; #include "GEOM_BaseDriver.hxx" @@ -81,6 +82,15 @@ Standard_EXPORT ~GEOMImpl_ProjectionDriver() {}; bool GetCreationInformation(std::string& theOperationName, std::vector& params); +private: + + TopoDS_Shape projectOnCylinder(const TopoDS_Shape &theShape, + const Standard_Real theRadius, + const Standard_Real theStartAngle, + const Standard_Real theAngleLength) const; + +public: + DEFINE_STANDARD_RTTI( GEOMImpl_ProjectionDriver ) }; diff --git a/src/GEOMImpl/GEOMImpl_Types.hxx b/src/GEOMImpl/GEOMImpl_Types.hxx index f4e151969..393b4303c 100644 --- a/src/GEOMImpl/GEOMImpl_Types.hxx +++ b/src/GEOMImpl/GEOMImpl_Types.hxx @@ -185,8 +185,9 @@ #define OFFSET_THICKENING 3 #define OFFSET_THICKENING_COPY 4 -#define PROJECTION_COPY 1 -#define PROJECTION_ON_WIRE 2 +#define PROJECTION_COPY 1 +#define PROJECTION_ON_WIRE 2 +#define PROJECTION_ON_CYLINDER 3 #define SCALE_SHAPE 1 #define SCALE_SHAPE_COPY 2 diff --git a/src/GEOMUtils/CMakeLists.txt b/src/GEOMUtils/CMakeLists.txt index 4368a6342..039990ab7 100755 --- a/src/GEOMUtils/CMakeLists.txt +++ b/src/GEOMUtils/CMakeLists.txt @@ -52,6 +52,9 @@ SET(_link_LIBRARIES SET(GEOMUtils_HEADERS GEOMUtils.hxx GEOMUtils_Hatcher.hxx + GEOMUtils_HTrsfCurve2d.hxx + GEOMUtils_Trsf2d.hxx + GEOMUtils_TrsfCurve2d.hxx GEOMUtils_XmlHandler.hxx ) # --- sources --- @@ -59,6 +62,9 @@ SET(GEOMUtils_HEADERS SET(GEOMUtils_SOURCES GEOMUtils.cxx GEOMUtils_Hatcher.cxx + GEOMUtils_HTrsfCurve2d.cxx + GEOMUtils_Trsf2d.cxx + GEOMUtils_TrsfCurve2d.cxx GEOMUtils_XmlHandler.cxx ) diff --git a/src/GEOMUtils/GEOMUtils_HTrsfCurve2d.cxx b/src/GEOMUtils/GEOMUtils_HTrsfCurve2d.cxx new file mode 100644 index 000000000..976d29690 --- /dev/null +++ b/src/GEOMUtils/GEOMUtils_HTrsfCurve2d.cxx @@ -0,0 +1,51 @@ +// Copyright (C) 2007-2014 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 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 +// version 2.1 of the License, or (at your option) any later version. +// +// 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 +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + + +#include + +namespace GEOMUtils { + IMPLEMENT_STANDARD_HANDLE (HTrsfCurve2d, Adaptor2d_HCurve2d); + IMPLEMENT_STANDARD_RTTIEXT(HTrsfCurve2d, Adaptor2d_HCurve2d); +} + +//======================================================================= +//function : TrsfCurve2d +//purpose : +//======================================================================= +GEOMUtils::HTrsfCurve2d::HTrsfCurve2d(const Handle(Geom2d_Curve) &theCurve, + const Trsf2d &theTrsf) +: myCurve (theCurve, theTrsf) +{ +} + +//======================================================================= +//function : TrsfCurve2d +//purpose : +//======================================================================= +GEOMUtils::HTrsfCurve2d::HTrsfCurve2d(const Handle(Geom2d_Curve) &theCurve, + const Standard_Real theUFirst, + const Standard_Real theULast, + const Trsf2d &theTrsf) +: myCurve (theCurve, theUFirst, theULast, theTrsf) +{ +} diff --git a/src/GEOMUtils/GEOMUtils_HTrsfCurve2d.hxx b/src/GEOMUtils/GEOMUtils_HTrsfCurve2d.hxx new file mode 100644 index 000000000..d37b7f293 --- /dev/null +++ b/src/GEOMUtils/GEOMUtils_HTrsfCurve2d.hxx @@ -0,0 +1,84 @@ +// Copyright (C) 2007-2014 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 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 +// version 2.1 of the License, or (at your option) any later version. +// +// 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 +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#ifndef _GEOMUtils_HTrsfCurve2d_HXX_ +#define _GEOMUtils_HTrsfCurve2d_HXX_ + + +#include + +#include + + +namespace GEOMUtils +{ + + class HTrsfCurve2d; + + DEFINE_STANDARD_HANDLE(HTrsfCurve2d, Adaptor2d_HCurve2d); + + /*! + * This class represents an adaptor curve that represents an original curve + * transformed by an anisotropic transformation. This is a class manipulated + * by handle. + */ + class HTrsfCurve2d : public Adaptor2d_HCurve2d + { + + public: + + /** + * Constructor. Initializes the object with the transformation parameters. + * Input parameters are not checked for validity. It is under responsibility + * of the caller. + */ + Standard_EXPORT HTrsfCurve2d(const Handle(Geom2d_Curve) &theCurve, + const Trsf2d &theTrsf); + + /** + * Constructor. Initializes the object with the curve, first and last + * parameters and transformation. Input parameters are not checked + * for validity. It is under responsibility of the caller. + */ + Standard_EXPORT HTrsfCurve2d(const Handle(Geom2d_Curve) &theCurve, + const Standard_Real theUFirst, + const Standard_Real theULast, + const Trsf2d &theTrsf); + + /** + * Redefined method from the base class. + */ + const Adaptor2d_Curve2d &Curve2d() const + { return myCurve; } + + private: + + TrsfCurve2d myCurve; + + public: + + DEFINE_STANDARD_RTTI(HTrsfCurve2d); + + }; +} + +#endif diff --git a/src/GEOMUtils/GEOMUtils_Trsf2d.cxx b/src/GEOMUtils/GEOMUtils_Trsf2d.cxx new file mode 100644 index 000000000..4938d4979 --- /dev/null +++ b/src/GEOMUtils/GEOMUtils_Trsf2d.cxx @@ -0,0 +1,110 @@ +// Copyright (C) 2007-2014 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 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 +// version 2.1 of the License, or (at your option) any later version. +// +// 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 +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + + +#include + + +//======================================================================= +//function : Trsf2d +//purpose : +//======================================================================= +GEOMUtils::Trsf2d::Trsf2d(const Standard_Real a11, + const Standard_Real a12, + const Standard_Real a13, + const Standard_Real a21, + const Standard_Real a22, + const Standard_Real a23) +: myA11(a11), + myA12(a12), + myA13(a13), + myA21(a21), + myA22(a22), + myA23(a23) +{ +} + +//======================================================================= +//function : TransformD0 +//purpose : +//======================================================================= +void GEOMUtils::Trsf2d::TransformD0(gp_Pnt2d &thePnt) const +{ + const Standard_Real aX = myA11*thePnt.X() + myA12*thePnt.Y() + myA13; + const Standard_Real aY = myA21*thePnt.X() + myA22*thePnt.Y() + myA23; + + thePnt.SetCoord(aX, aY); +} + +//======================================================================= +//function : TransformD1 +//purpose : +//======================================================================= +void GEOMUtils::Trsf2d::TransformD1(gp_Pnt2d &thePnt, + gp_Vec2d &theVec1) const +{ + TransformVector(thePnt, theVec1); + TransformD0(thePnt); +} + +//======================================================================= +//function : TransformD2 +//purpose : +//======================================================================= +void GEOMUtils::Trsf2d::TransformD2(gp_Pnt2d &thePnt, + gp_Vec2d &theVec1, + gp_Vec2d &theVec2) const +{ + TransformVector(thePnt, theVec1); + TransformVector(thePnt, theVec2); + TransformD0(thePnt); +} + +//======================================================================= +//function : TransformD3 +//purpose : +//======================================================================= +void GEOMUtils::Trsf2d::TransformD3(gp_Pnt2d &thePnt, + gp_Vec2d &theVec1, + gp_Vec2d &theVec2, + gp_Vec2d &theVec3) const +{ + TransformVector(thePnt, theVec1); + TransformVector(thePnt, theVec2); + TransformVector(thePnt, theVec3); + TransformD0(thePnt); +} + +//======================================================================= +//function : TransformVector +//purpose : +//======================================================================= +void GEOMUtils::Trsf2d::TransformVector(const gp_Pnt2d &thePnt, + gp_Vec2d &theVec) const +{ + gp_Pnt2d aP0(thePnt.XY()); + gp_Pnt2d aP1(thePnt.XY().Added(theVec.XY())); + + TransformD0(aP0); + TransformD0(aP1); + theVec.SetXY(aP1.XY().Subtracted(aP0.XY())); +} diff --git a/src/GEOMUtils/GEOMUtils_Trsf2d.hxx b/src/GEOMUtils/GEOMUtils_Trsf2d.hxx new file mode 100644 index 000000000..c287f90d8 --- /dev/null +++ b/src/GEOMUtils/GEOMUtils_Trsf2d.hxx @@ -0,0 +1,134 @@ +// Copyright (C) 2007-2014 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 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 +// version 2.1 of the License, or (at your option) any later version. +// +// 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 +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#ifndef _GEOMUtils_Trsf2d_HXX_ +#define _GEOMUtils_Trsf2d_HXX_ + + +#include +#include +#include +#include +#include + + +/*! + * This class represents a non-persistent transformation in 2D space. + * The transformations can be represented as follow : + * + * V1 V2 T XY XY + * | a11 a12 a13 | | x | | x'| + * | a21 a22 a23 | | y | | y'| + * | 0 0 1 | | 1 | | 1 | + + * where {V1, V2} defines the vectorial part of the transformation + * and T defines the translation part of the transformation. + * This transformation can change the nature of the objects if it is + * anisotropic. + */ +namespace GEOMUtils +{ + class Trsf2d + { + + public: + + /** + * Constructor. Initializes the object with the transformation parameters. + * Input parameters are not checked for validity. It is under responsibility + * of the caller. + */ + Standard_EXPORT Trsf2d(const Standard_Real a11, + const Standard_Real a12, + const Standard_Real a13, + const Standard_Real a21, + const Standard_Real a22, + const Standard_Real a23); + + /** + * Transform the point. The passed parameter is modified to have + * a transformed value. + * + * \param thePnt the point. + */ + Standard_EXPORT void TransformD0(gp_Pnt2d &thePnt)const; + + /** + * Transform the point and the first derivative vector. The passed + * parameters are modified to have a transformed value. + * + * \param thePnt the point. + * \param theVec1 the first derivative vector. + */ + Standard_EXPORT void TransformD1(gp_Pnt2d &thePnt, + gp_Vec2d &theVec1) const; + + /** + * Transform the point, the first and second derivative vectors. The passed + * parameters are modified to have a transformed value. + * + * \param thePnt the point. + * \param theVec1 the first derivative vector. + * \param theVec2 the second derivative vector. + */ + Standard_EXPORT void TransformD2(gp_Pnt2d &thePnt, + gp_Vec2d &theVec1, + gp_Vec2d &theVec2) const; + + /** + * Transform the point, the first, second and third derivative vectors. + * The passed parameters are modified to have a transformed value. + * + * \param thePnt the point. + * \param theVec1 the first derivative vector. + * \param theVec2 the second derivative vector. + * \param theVec2 the third derivative vector. + */ + Standard_EXPORT void TransformD3(gp_Pnt2d &thePnt, + gp_Vec2d &theVec1, + gp_Vec2d &theVec2, + gp_Vec2d &theVec3) const; + + private: + + /** + * Transform the vector. + * + * \param thePnt the point. + * \param theVec the vector. + */ + void TransformVector(const gp_Pnt2d &thePnt, + gp_Vec2d &theVec) const; + + private: + + Standard_Real myA11; + Standard_Real myA12; + Standard_Real myA13; + Standard_Real myA21; + Standard_Real myA22; + Standard_Real myA23; + + }; +} + +#endif diff --git a/src/GEOMUtils/GEOMUtils_TrsfCurve2d.cxx b/src/GEOMUtils/GEOMUtils_TrsfCurve2d.cxx new file mode 100644 index 000000000..fe0707eb9 --- /dev/null +++ b/src/GEOMUtils/GEOMUtils_TrsfCurve2d.cxx @@ -0,0 +1,382 @@ +// Copyright (C) 2007-2014 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 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 +// version 2.1 of the License, or (at your option) any later version. +// +// 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 +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + + +#include +#include + +//======================================================================= +//function : TrsfCurve2d +//purpose : +//======================================================================= +GEOMUtils::TrsfCurve2d::TrsfCurve2d(const Handle(Geom2d_Curve) &theCurve, + const Trsf2d &theTrsf) +: myCurve (theCurve), + myTrsf (theTrsf) +{ +} + +//======================================================================= +//function : TrsfCurve2d +//purpose : +//======================================================================= +GEOMUtils::TrsfCurve2d::TrsfCurve2d(const Handle(Geom2d_Curve) &theCurve, + const Standard_Real theUFirst, + const Standard_Real theULast, + const Trsf2d &theTrsf) +: myCurve (theCurve, theUFirst, theULast), + myTrsf (theTrsf) +{ +} + +//======================================================================= +//function : FirstParameter +//purpose : +//======================================================================= +Standard_Real GEOMUtils::TrsfCurve2d::FirstParameter() const +{ + return myCurve.FirstParameter(); +} + +//======================================================================= +//function : LastParameter +//purpose : +//======================================================================= +Standard_Real GEOMUtils::TrsfCurve2d::LastParameter() const +{ + return myCurve.LastParameter(); +} + +//======================================================================= +//function : Curve +//purpose : +//======================================================================= +const Handle(Geom2d_Curve) &GEOMUtils::TrsfCurve2d::Curve() const +{ + return myCurve.Curve(); +} + +//======================================================================= +//function : GetType +//purpose : +//======================================================================= +GeomAbs_CurveType GEOMUtils::TrsfCurve2d::GetType() const +{ + return GeomAbs_OtherCurve; +} + +//======================================================================= +//function : Load +//purpose : +//======================================================================= +void GEOMUtils::TrsfCurve2d::Load(const Handle(Geom2d_Curve) &C) +{ + myCurve.Load(C); +} + +//======================================================================= +//function : Load +//purpose : +//======================================================================= +void GEOMUtils::TrsfCurve2d::Load(const Handle(Geom2d_Curve) &C, + const Standard_Real UFirst, + const Standard_Real ULast) +{ + myCurve.Load(C, UFirst, ULast); +} + +//======================================================================= +//function : Continuity +//purpose : +//======================================================================= +GeomAbs_Shape GEOMUtils::TrsfCurve2d::Continuity() const +{ + return myCurve.Continuity(); +} + +//======================================================================= +//function : NbIntervals +//purpose : +//======================================================================= +Standard_Integer GEOMUtils::TrsfCurve2d::NbIntervals + (const GeomAbs_Shape S) const +{ + return myCurve.NbIntervals(S); +} + +//======================================================================= +//function : Intervals +//purpose : +//======================================================================= +void GEOMUtils::TrsfCurve2d::Intervals(TColStd_Array1OfReal &T, + const GeomAbs_Shape S) const +{ + myCurve.Intervals(T, S); +} + +//======================================================================= +//function : Trim +//purpose : +//======================================================================= +Handle(Adaptor2d_HCurve2d) GEOMUtils::TrsfCurve2d::Trim + (const Standard_Real First, const Standard_Real Last, + const Standard_Real /*Tol*/) const +{ + Handle(Geom2d_Curve) aCurve = myCurve.Curve(); + GEOMUtils::Handle(HTrsfCurve2d) aAHCurve = + new GEOMUtils::HTrsfCurve2d(aCurve, First, Last, myTrsf); + + return aAHCurve; +} + +//======================================================================= +//function : IsClosed +//purpose : +//======================================================================= +Standard_Boolean GEOMUtils::TrsfCurve2d::IsClosed() const +{ + return myCurve.IsClosed(); +} + +//======================================================================= +//function : IsPeriodic +//purpose : +//======================================================================= +Standard_Boolean GEOMUtils::TrsfCurve2d::IsPeriodic() const +{ + return myCurve.IsPeriodic(); +} + +//======================================================================= +//function : Period +//purpose : +//======================================================================= +Standard_Real GEOMUtils::TrsfCurve2d::Period() const +{ + return myCurve.Period(); +} + +//======================================================================= +//function : Value +//purpose : +//======================================================================= +gp_Pnt2d GEOMUtils::TrsfCurve2d::Value(const Standard_Real U) const +{ + gp_Pnt2d aPnt = myCurve.Value(U); + + myTrsf.TransformD0(aPnt); + + return aPnt; +} + +//======================================================================= +//function : D0 +//purpose : +//======================================================================= +void GEOMUtils::TrsfCurve2d::D0(const Standard_Real U, gp_Pnt2d &P) const +{ + myCurve.D0(U, P); + myTrsf.TransformD0(P); +} + +//======================================================================= +//function : D1 +//purpose : +//======================================================================= +void GEOMUtils::TrsfCurve2d::D1(const Standard_Real U, + gp_Pnt2d &P, gp_Vec2d &V) const +{ + myCurve.D1(U, P, V); + myTrsf.TransformD1(P, V); +} + +//======================================================================= +//function : D2 +//purpose : +//======================================================================= +void GEOMUtils::TrsfCurve2d::D2(const Standard_Real U, gp_Pnt2d &P, + gp_Vec2d &V1, gp_Vec2d &V2) const +{ + myCurve.D2(U, P, V1, V2); + myTrsf.TransformD2(P, V1, V2); +} + +//======================================================================= +//function : D3 +//purpose : +//======================================================================= +void GEOMUtils::TrsfCurve2d::D3(const Standard_Real U, gp_Pnt2d &P, + gp_Vec2d &V1, gp_Vec2d &V2, gp_Vec2d &V3) const +{ + myCurve.D3(U, P, V1, V2, V3); + myTrsf.TransformD3(P, V1, V2, V3); +} + +//======================================================================= +//function : DN +//purpose : +//======================================================================= +gp_Vec2d GEOMUtils::TrsfCurve2d::DN(const Standard_Real U, + const Standard_Integer N) const +{ + gp_Pnt2d aPnt = myCurve.Value(U); + gp_Vec2d aVec = myCurve.DN(U, N); + + myTrsf.TransformD1(aPnt, aVec); +} + +//======================================================================= +//function : Resolution +//purpose : +//======================================================================= +Standard_Real GEOMUtils::TrsfCurve2d::Resolution(const Standard_Real Ruv) const +{ + return Precision::Parametric(Ruv); +} + +//======================================================================= +//function : Line +//purpose : +//======================================================================= +gp_Lin2d GEOMUtils::TrsfCurve2d::Line() const +{ + Standard_NoSuchObject::Raise(); + + return gp_Lin2d(); +} + +//======================================================================= +//function : Circle +//purpose : +//======================================================================= +gp_Circ2d GEOMUtils::TrsfCurve2d::Circle() const +{ + Standard_NoSuchObject::Raise(); + + return gp_Circ2d(); +} + +//======================================================================= +//function : Ellipse +//purpose : +//======================================================================= +gp_Elips2d GEOMUtils::TrsfCurve2d::Ellipse() const +{ + Standard_NoSuchObject::Raise(); + + return gp_Elips2d(); +} + +//======================================================================= +//function : Hyperbola +//purpose : +//======================================================================= +gp_Hypr2d GEOMUtils::TrsfCurve2d::Hyperbola() const +{ + Standard_NoSuchObject::Raise(); + + return gp_Hypr2d(); +} + +//======================================================================= +//function : Parabola +//purpose : +//======================================================================= +gp_Parab2d GEOMUtils::TrsfCurve2d::Parabola() const +{ + Standard_NoSuchObject::Raise(); + + return gp_Parab2d(); +} + +//======================================================================= +//function : Degree +//purpose : +//======================================================================= +Standard_Integer GEOMUtils::TrsfCurve2d::Degree() const +{ + Standard_NoSuchObject::Raise(); + + return 0; +} + +//======================================================================= +//function : IsRational +//purpose : +//======================================================================= +Standard_Boolean GEOMUtils::TrsfCurve2d::IsRational() const +{ + return Standard_False; +} + +//======================================================================= +//function : NbPoles +//purpose : +//======================================================================= +Standard_Integer GEOMUtils::TrsfCurve2d::NbPoles() const +{ + Standard_NoSuchObject::Raise(); + + return 0; +} + +//======================================================================= +//function : NbKnots +//purpose : +//======================================================================= +Standard_Integer GEOMUtils::TrsfCurve2d::NbKnots() const +{ + Standard_NoSuchObject::Raise(); + + return 0; +} + +//======================================================================= +//function : Bezier +//purpose : +//======================================================================= +Handle(Geom2d_BezierCurve) GEOMUtils::TrsfCurve2d::Bezier() const +{ + Standard_NoSuchObject::Raise(); + + return NULL; +} + +//======================================================================= +//function : BSpline +//purpose : +//======================================================================= +Handle(Geom2d_BSplineCurve) GEOMUtils::TrsfCurve2d::BSpline() const +{ + Standard_NoSuchObject::Raise(); + + return NULL; +} + +//======================================================================= +//function : NbSamples +//purpose : +//======================================================================= +Standard_Integer GEOMUtils::TrsfCurve2d::NbSamples() const +{ + return myCurve.NbSamples(); +} diff --git a/src/GEOMUtils/GEOMUtils_TrsfCurve2d.hxx b/src/GEOMUtils/GEOMUtils_TrsfCurve2d.hxx new file mode 100644 index 000000000..b3bd19433 --- /dev/null +++ b/src/GEOMUtils/GEOMUtils_TrsfCurve2d.hxx @@ -0,0 +1,242 @@ +// Copyright (C) 2007-2014 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 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 +// version 2.1 of the License, or (at your option) any later version. +// +// 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 +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#ifndef _GEOMUtils_TrsfCurve2d_HXX_ +#define _GEOMUtils_TrsfCurve2d_HXX_ + + +#include + +#include +#include +#include +#include +#include + + +namespace GEOMUtils +{ + /*! + * This class represents an adaptor curve that represents an original curve + * transformed by an anisotropic transformation. + */ + class TrsfCurve2d : public Adaptor2d_Curve2d + { + + public: + + /** + * Constructor. Initializes the object with the transformation parameters. + * Input parameters are not checked for validity. It is under responsibility + * of the caller. + */ + Standard_EXPORT TrsfCurve2d(const Handle(Geom2d_Curve) &theCurve, + const Trsf2d &theTrsf); + + /** + * Constructor. Initializes the object with the curve, first and last + * parameters and transformation. Input parameters are not checked + * for validity. It is under responsibility of the caller. + */ + Standard_EXPORT TrsfCurve2d(const Handle(Geom2d_Curve) &theCurve, + const Standard_Real theUFirst, + const Standard_Real theULast, + const Trsf2d &theTrsf); + + /** + * Redefined method from the base class. + */ + Standard_EXPORT Standard_Real FirstParameter() const; + + /** + * Redefined method from the base class. + */ + Standard_EXPORT Standard_Real LastParameter() const; + + /** + * Redefined method from the base class. + */ + Standard_EXPORT const Handle(Geom2d_Curve)& Curve() const; + + /** + * Redefined method from the base class. + */ + Standard_EXPORT GeomAbs_CurveType GetType() const; + + /** + * Redefined method from the base class. + */ + Standard_EXPORT void Load(const Handle(Geom2d_Curve) &C); + + /** + * Redefined method from the base class. + */ + Standard_EXPORT void Load(const Handle(Geom2d_Curve) &C, + const Standard_Real UFirst, + const Standard_Real ULast); + + /** + * Redefined method from the base class. + */ + Standard_EXPORT GeomAbs_Shape Continuity() const; + + /** + * Redefined method from the base class. + */ + Standard_EXPORT Standard_Integer NbIntervals(const GeomAbs_Shape S) const; + + /** + * Redefined method from the base class. + */ + Standard_EXPORT void Intervals(TColStd_Array1OfReal &T, + const GeomAbs_Shape S) const; + + /** + * Redefined method from the base class. + */ + Standard_EXPORT Handle(Adaptor2d_HCurve2d) Trim + (const Standard_Real First, const Standard_Real Last, + const Standard_Real ) const; + + /** + * Redefined method from the base class. + */ + Standard_EXPORT Standard_Boolean IsClosed() const; + + /** + * Redefined method from the base class. + */ + Standard_EXPORT Standard_Boolean IsPeriodic() const; + + /** + * Redefined method from the base class. + */ + Standard_EXPORT Standard_Real Period() const; + + /** + * Redefined method from the base class. + */ + Standard_EXPORT gp_Pnt2d Value(const Standard_Real U) const; + + /** + * Redefined method from the base class. + */ + Standard_EXPORT void D0(const Standard_Real U, gp_Pnt2d &P) const; + + /** + * Redefined method from the base class. + */ + Standard_EXPORT void D1(const Standard_Real U, + gp_Pnt2d &P, gp_Vec2d &V) const; + + /** + * Redefined method from the base class. + */ + Standard_EXPORT void D2(const Standard_Real U, gp_Pnt2d &P, + gp_Vec2d &V1, gp_Vec2d &V2) const; + + /** + * Redefined method from the base class. + */ + Standard_EXPORT void D3(const Standard_Real U, gp_Pnt2d &P, + gp_Vec2d &V1, gp_Vec2d &V2, gp_Vec2d &V3) const; + + /** + * Redefined method from the base class. + */ + Standard_EXPORT gp_Vec2d DN(const Standard_Real U, + const Standard_Integer N) const; + + /** + * Redefined method from the base class. + */ + Standard_EXPORT Standard_Real Resolution(const Standard_Real Ruv) const; + + /** + * Redefined method from the base class. + */ + Standard_EXPORT gp_Lin2d Line() const; + + /** + * Redefined method from the base class. + */ + Standard_EXPORT gp_Circ2d Circle() const; + + /** + * Redefined method from the base class. + */ + Standard_EXPORT gp_Elips2d Ellipse() const; + + /** + * Redefined method from the base class. + */ + Standard_EXPORT gp_Hypr2d Hyperbola() const; + + /** + * Redefined method from the base class. + */ + Standard_EXPORT gp_Parab2d Parabola() const; + + /** + * Redefined method from the base class. + */ + Standard_EXPORT Standard_Integer Degree() const; + + /** + * Redefined method from the base class. + */ + Standard_EXPORT Standard_Boolean IsRational() const; + + /** + * Redefined method from the base class. + */ + Standard_EXPORT Standard_Integer NbPoles() const; + + /** + * Redefined method from the base class. + */ + Standard_EXPORT Standard_Integer NbKnots() const; + + /** + * Redefined method from the base class. + */ + Standard_EXPORT Handle(Geom2d_BezierCurve) Bezier() const; + + /** + * Redefined method from the base class. + */ + Standard_EXPORT Handle(Geom2d_BSplineCurve) BSpline() const; + + /** + * Redefined method from the base class. + */ + Standard_EXPORT Standard_Integer NbSamples() const; + + private: + + Geom2dAdaptor_Curve myCurve; + Trsf2d myTrsf; + + }; +} + +#endif diff --git a/src/GEOM_I/GEOM_ITransformOperations_i.cc b/src/GEOM_I/GEOM_ITransformOperations_i.cc index 2281957e3..c18c87b6c 100644 --- a/src/GEOM_I/GEOM_ITransformOperations_i.cc +++ b/src/GEOM_I/GEOM_ITransformOperations_i.cc @@ -1392,3 +1392,37 @@ GEOM::GEOM_Object_ptr GEOM_ITransformOperations_i::RecomputeObject return aGEOMObject._retn(); } + +//============================================================================= +/*! + * MakeProjectionOnCylinder + */ +//============================================================================= +GEOM::GEOM_Object_ptr GEOM_ITransformOperations_i::MakeProjectionOnCylinder + (GEOM::GEOM_Object_ptr theObject, + CORBA::Double theRadius, + CORBA::Double theStartAngle, + CORBA::Double theAngleLength) +{ + GEOM::GEOM_Object_var aGEOMObject; + + //Set a not done flag + GetOperations()->SetNotDone(); + + //Get the object + Handle(GEOM_Object) anObject = GetObjectImpl(theObject); + + if (anObject.IsNull()) { + return aGEOMObject._retn(); + } + + //Perform the transformation + Handle(GEOM_Object) aResObject = GetOperations()->MakeProjectionOnCylinder + (anObject, theRadius, theStartAngle, theAngleLength); + + if (!GetOperations()->IsDone() || aResObject.IsNull()) { + return aGEOMObject._retn(); + } + + return GetObject(aResObject); +} diff --git a/src/GEOM_I/GEOM_ITransformOperations_i.hh b/src/GEOM_I/GEOM_ITransformOperations_i.hh index 40a5903ed..e507c1f77 100644 --- a/src/GEOM_I/GEOM_ITransformOperations_i.hh +++ b/src/GEOM_I/GEOM_ITransformOperations_i.hh @@ -197,6 +197,11 @@ class GEOM_I_EXPORT GEOM_ITransformOperations_i : GEOM::GEOM_Object_ptr RecomputeObject (GEOM::GEOM_Object_ptr theObject); + GEOM::GEOM_Object_ptr MakeProjectionOnCylinder + (GEOM::GEOM_Object_ptr theObject, + CORBA::Double theRadius, + CORBA::Double theStartAngle, + CORBA::Double theAngleLength); ::GEOMImpl_ITransformOperations* GetOperations() { return (::GEOMImpl_ITransformOperations*)GetImpl(); } }; diff --git a/src/GEOM_SWIG/GEOM_TestAll.py b/src/GEOM_SWIG/GEOM_TestAll.py index 3aa3eff61..683918508 100644 --- a/src/GEOM_SWIG/GEOM_TestAll.py +++ b/src/GEOM_SWIG/GEOM_TestAll.py @@ -272,6 +272,7 @@ def TestAll (geompy, math): Position2 = geompy.PositionAlongPath(Box, Arc, 0.5, 1, 0) #(2 GEOM_Object, 1 Double, 2 Bool)->GEOM_Object Offset = geompy.MakeOffset(Box, 10.) #(GEOM_Object, Double)->GEOM_Object ProjOnWire = geompy.MakeProjectionOnWire(p0, Wire) + ProjOnCyl = geompy.MakeProjectionOnCylinder(Wire, 100) Orientation = geompy.ChangeOrientation(Box) ExtEdge = geompy.ExtendEdge(Edge1, -0.3, 1.3) ExtFace = geompy.ExtendFace(Face5, -0.3, 1.3, -0.1, 1.1) @@ -497,6 +498,7 @@ def TestAll (geompy, math): id_Offset = geompy.addToStudy(Offset, "Offset") id_Orientation = geompy.addToStudy(Orientation, "Orientation") id_ProjOnWire = geompy.addToStudy(ProjOnWire[1], "ProjOnWire") + id_ProjOnCyl = geompy.addToStudy(ProjOnCyl, "ProjOnCyl") id_ExtEdge = geompy.addToStudy(ExtEdge, "ExtendedEdge") id_ExtFace = geompy.addToStudy(ExtFace, "ExtendedFace") id_Surface = geompy.addToStudy(Surface, "Surface From Face") diff --git a/src/GEOM_SWIG/geomBuilder.py b/src/GEOM_SWIG/geomBuilder.py index 531c1bf18..5287a1194 100644 --- a/src/GEOM_SWIG/geomBuilder.py +++ b/src/GEOM_SWIG/geomBuilder.py @@ -9403,6 +9403,67 @@ class geomBuilder(object, GEOM._objref_GEOM_Gen): anObj = self.MultiRotate2DByStep(aShape, aVec, anAngle, nbtimes1, aStep, nbtimes2, theName) return anObj + ## + # Compute a wire or a face that represents a projection of the source + # shape onto cylinder. The cylinder's coordinate system is the same + # as the global coordinate system. + # + # @param theObject The object to be projected. It can be either + # a planar wire or a face. + # @param theRadius The radius of the cylinder. + # @param theStartAngle The starting angle in radians from + # the cylinder's X axis around Z axis. The angle from which + # the projection is started. + # @param theAngleLength The projection length angle in radians. + # The angle in which to project the total length of the wire. + # If it is negative the projection is not scaled and natural + # wire length is kept for the projection. + # @param theName Object name; when specified, this parameter is used + # for result publication in the study. Otherwise, if automatic + # publication is switched on, default value is used for result name. + # + # @return New GEOM.GEOM_Object, containing the result shape. The result + # represents a wire or a face that represents a projection of + # the source shape onto a cylinder. + # + # @ref tui_projection "Example" + def MakeProjectionOnCylinder (self, theObject, theRadius, + theStartAngle=0.0, theAngleLength=-1.0, + theName=None): + """ + Compute a wire or a face that represents a projection of the source + shape onto cylinder. The cylinder's coordinate system is the same + as the global coordinate system. + + Parameters: + theObject The object to be projected. It can be either + a planar wire or a face. + theRadius The radius of the cylinder. + theStartAngle The starting angle in radians from the cylinder's X axis + around Z axis. The angle from which the projection is started. + theAngleLength The projection length angle in radians. The angle in which + to project the total length of the wire. If it is negative the + projection is not scaled and natural wire length is kept for + the projection. + theName Object name; when specified, this parameter is used + for result publication in the study. Otherwise, if automatic + publication is switched on, default value is used for result name. + + Returns: + New GEOM.GEOM_Object, containing the result shape. The result + represents a wire or a face that represents a projection of + the source shape onto a cylinder. + """ + # Example: see GEOM_TestAll.py + theRadius, theStartAngle, theAngleLength, Parameters = ParseParameters( + theRadius, theStartAngle, theAngleLength) + anObj = self.TrsfOp.MakeProjectionOnCylinder(theObject, theRadius, + theStartAngle, theAngleLength) + RaiseIfFailed("MakeProjectionOnCylinder", self.TrsfOp) + anObj.SetParameters(Parameters) + self._autoPublish(anObj, theName, "projection") + return anObj + # end of l3_transform ## @} diff --git a/src/TransformationGUI/CMakeLists.txt b/src/TransformationGUI/CMakeLists.txt index e60a2e84b..2b4b75858 100755 --- a/src/TransformationGUI/CMakeLists.txt +++ b/src/TransformationGUI/CMakeLists.txt @@ -75,6 +75,7 @@ SET(TransformationGUI_HEADERS TransformationGUI_ScaleDlg.h TransformationGUI_OffsetDlg.h TransformationGUI_ProjectionDlg.h + TransformationGUI_ProjectionOnCylDlg.h TransformationGUI_PositionDlg.h ) @@ -89,6 +90,7 @@ SET(_moc_HEADERS TransformationGUI_ScaleDlg.h TransformationGUI_OffsetDlg.h TransformationGUI_ProjectionDlg.h + TransformationGUI_ProjectionOnCylDlg.h TransformationGUI_PositionDlg.h ) @@ -111,6 +113,7 @@ SET(TransformationGUI_SOURCES TransformationGUI_ScaleDlg.cxx TransformationGUI_OffsetDlg.cxx TransformationGUI_ProjectionDlg.cxx + TransformationGUI_ProjectionOnCylDlg.cxx TransformationGUI_PositionDlg.cxx ${_moc_SOURCES} ${_uic_files} diff --git a/src/TransformationGUI/TransformationGUI.cxx b/src/TransformationGUI/TransformationGUI.cxx index 47be80cd1..943e2126b 100644 --- a/src/TransformationGUI/TransformationGUI.cxx +++ b/src/TransformationGUI/TransformationGUI.cxx @@ -49,6 +49,7 @@ #include "TransformationGUI_OffsetDlg.h" // Method OFFSET #include "TransformationGUI_ProjectionDlg.h" // Method PROJECTION #include "TransformationGUI_PositionDlg.h" // Method POSITION +#include "TransformationGUI_ProjectionOnCylDlg.h" // Method PROJECTION ON CYLINDER //======================================================================= // function : TransformationGUI() @@ -102,6 +103,9 @@ bool TransformationGUI::OnGUIEvent( int theCommandID, SUIT_Desktop* parent ) case GEOMOp::OpProjection: // PROJECTION aDlg = new TransformationGUI_ProjectionDlg( getGeometryGUI(), parent ); break; + case GEOMOp::OpProjOnCyl: // PROJECTION ON CYLINDER + aDlg = new TransformationGUI_ProjectionOnCylDlg( getGeometryGUI(), parent ); + break; case GEOMOp::OpMultiTranslate: // MULTI TRANSLATION aDlg = new TransformationGUI_MultiTranslationDlg( getGeometryGUI(), parent ); break; diff --git a/src/TransformationGUI/TransformationGUI_ProjectionOnCylDlg.cxx b/src/TransformationGUI/TransformationGUI_ProjectionOnCylDlg.cxx new file mode 100644 index 000000000..d3efac641 --- /dev/null +++ b/src/TransformationGUI/TransformationGUI_ProjectionOnCylDlg.cxx @@ -0,0 +1,360 @@ +// Copyright (C) 2007-2014 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 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 +// version 2.1 of the License, or (at your option) any later version. +// +// 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 +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +// GEOM GEOMGUI : GUI for Geometry component +// File : TransformationGUI_ProjectionOnCylDlg.cxx +// Author : Sergey KHROMOV, Open CASCADE S.A.S. + +#include "TransformationGUI_ProjectionOnCylDlg.h" + +#include +#include +#include + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include + +//================================================================================= +// class : TransformationGUI_ProjectionOnCylDlg() +// purpose : Constructs a TransformationGUI_ProjectionOnCylDlg which is +// a child of 'parent', with the name 'name' and widget flags set to +// 'f'. The dialog will by default be modeless, unless you set +// 'modal' to TRUE to construct a modal dialog. +//================================================================================= +TransformationGUI_ProjectionOnCylDlg::TransformationGUI_ProjectionOnCylDlg +(GeometryGUI* theGeometryGUI, QWidget* parent, bool modal, Qt::WindowFlags fl) + : GEOMBase_Skeleton (theGeometryGUI, parent, modal, fl), + myObjectName (0), + mySelButton (0), + myRadiusSpin (0), + myStartAngleSpin (0), + myUseAngleLen (0), + myAngleLenSpin (0) +{ + SUIT_ResourceMgr* aResMgr = myGeomGUI->getApp()->resourceMgr(); + QPixmap image0 (aResMgr->loadPixmap("GEOM", tr("ICO_DLG_PROJ_ON_CYL"))); + QPixmap image1 (aResMgr->loadPixmap("GEOM", tr("ICON_SELECT"))); + + setWindowTitle(tr("GEOM_PROJ_ON_CYL_TITLE")); + + /***************************************************************/ + mainFrame()->GroupConstructors->setTitle(tr("GEOM_PROJECTION_TITLE")); + mainFrame()->RadioButton1->setIcon(image0); + mainFrame()->RadioButton2->setAttribute(Qt::WA_DeleteOnClose); + mainFrame()->RadioButton2->close(); + mainFrame()->RadioButton3->setAttribute(Qt::WA_DeleteOnClose); + mainFrame()->RadioButton3->close(); + + QGroupBox *aGrpParams = + new QGroupBox(tr("GEOM_ARGUMENTS"), centralWidget()); + QGridLayout *aParamsLayout = new QGridLayout(aGrpParams); + QLabel *anObjLbl = new QLabel(tr("GEOM_OBJECT"), aGrpParams); + QLabel *aRadiusLbl = new QLabel(tr("GEOM_RADIUS"), aGrpParams); + QLabel *aStartAngleLbl = + new QLabel(tr("GEOM_PROJ_ON_CYL_START_ANGLE"), aGrpParams); + QLabel *anAngleLenLbl = + new QLabel(tr("GEOM_PROJ_ON_CYL_LENGTH_ANGLE"), aGrpParams); + + myObjectName = new QLineEdit(aGrpParams); + mySelButton = new QPushButton(aGrpParams); + myRadiusSpin = new SalomeApp_DoubleSpinBox(aGrpParams); + myStartAngleSpin = new SalomeApp_DoubleSpinBox(aGrpParams); + myUseAngleLen = new QCheckBox(aGrpParams); + myAngleLenSpin = new SalomeApp_DoubleSpinBox(aGrpParams); + + myObjectName->setReadOnly(true); + mySelButton->setIcon(image1); + mySelButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); + myUseAngleLen->setChecked(false); + + aParamsLayout->setMargin(9); + aParamsLayout->setSpacing(6); + aParamsLayout->addWidget(anObjLbl, 0, 1); + aParamsLayout->addWidget(mySelButton, 0, 2); + aParamsLayout->addWidget(myObjectName, 0, 3); + aParamsLayout->addWidget(aRadiusLbl, 1, 1); + aParamsLayout->addWidget(myRadiusSpin, 1, 2, 1, 2); + aParamsLayout->addWidget(aStartAngleLbl, 2, 1); + aParamsLayout->addWidget(myStartAngleSpin, 2, 2, 1, 2); + aParamsLayout->addWidget(myUseAngleLen, 3, 0); + aParamsLayout->addWidget(anAngleLenLbl, 3, 1); + aParamsLayout->addWidget(myAngleLenSpin, 3, 2, 1, 2); + + QVBoxLayout* layout = new QVBoxLayout( centralWidget() ); + layout->setMargin( 0 ); layout->setSpacing( 6 ); + layout->addWidget( aGrpParams ); + + /***************************************************************/ + + setHelpFileName("projection_on_cylinder_operation_page.html"); + + Init(); +} + +//================================================================================= +// function : ~TransformationGUI_ProjectionOnCylDlg() +// purpose : Destroys the object and frees any allocated resources +//================================================================================= +TransformationGUI_ProjectionOnCylDlg::~TransformationGUI_ProjectionOnCylDlg() +{ + // no need to delete child widgets, Qt does it all for us +} + +//================================================================================= +// function : Init() +// purpose : +//================================================================================= +void TransformationGUI_ProjectionOnCylDlg::Init() +{ + showOnlyPreviewControl(); + + SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr(); + double aStep = resMgr->doubleValue("Geometry", "SettingsGeomStep", 100); + double aSpecificStep = 5; + double aRadius = 100.0; + double aStartAngle = 0.; + double anAngleLen = 360.; + + initSpinBox(myRadiusSpin, 0.00001, COORD_MAX, aStep, "length_precision"); + initSpinBox(myStartAngleSpin, -180., 180., aSpecificStep, "angle_precision"); + initSpinBox(myAngleLenSpin, 0.00001, COORD_MAX, aSpecificStep, "angle_precision"); + + myRadiusSpin->setValue(aRadius); + myStartAngleSpin->setValue(aStartAngle); + myAngleLenSpin->setValue(anAngleLen); + + myObjectName->setText(""); + myUseAngleLen->setChecked(true); + + // signals and slots connections + connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk())); + connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply())); + + connect(mySelButton, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument())); + connect(myRadiusSpin, SIGNAL(valueChanged(double)), this, SLOT(processPreview())); + connect(myStartAngleSpin, SIGNAL(valueChanged(double)), this, SLOT(processPreview())); + connect(myAngleLenSpin, SIGNAL(valueChanged(double)), this, SLOT(processPreview())); + connect(myUseAngleLen, SIGNAL(clicked()), this, SLOT(SetUseLengthAngle())); + + connect(myGeomGUI->getApp()->selectionMgr(),SIGNAL(currentSelectionChanged()), + this, SLOT(SelectionIntoArgument())); + + initName(tr("GEOM_PROJECTION_NAME")); + + buttonOk()->setEnabled(false); + buttonApply()->setEnabled(false); + + activateSelection(); + SelectionIntoArgument(); +} + +//================================================================================= +// function : ClickOnOk() +// purpose : +//================================================================================= +void TransformationGUI_ProjectionOnCylDlg::ClickOnOk() +{ + setIsApplyAndClose( true ); + if (ClickOnApply()) + ClickOnCancel(); +} + +//================================================================================= +// function : ClickOnApply() +// purpose : +//================================================================================= +bool TransformationGUI_ProjectionOnCylDlg::ClickOnApply() +{ + if ( !onAccept() ) + return false; + + initName(); + return true; +} + +//================================================================================= +// function : SelectionIntoArgument() +// purpose : Called when selection is changed or on dialog initialization or activation +//================================================================================= +void TransformationGUI_ProjectionOnCylDlg::SelectionIntoArgument() +{ + erasePreview(); + myObj = GEOM::GEOM_Object::_nil(); + + LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr(); + SALOME_ListIO aSelList; + aSelMgr->selectedObjects(aSelList); + + if (aSelList.Extent() == 1) { + // Single object is selected. + GEOM::GEOM_Object_var aSelectedObject = + GEOMBase::ConvertIOinGEOMObject( aSelList.First() ); + + if (aSelectedObject->_is_nil()) { + // Null object. + myObjectName->setText(""); + buttonOk()->setEnabled(false); + buttonApply()->setEnabled(false); + } else { + // Not Null object. + myObj = aSelectedObject; + myObjectName->setText(GEOMBase::GetName(myObj)); + buttonOk()->setEnabled(true); + buttonApply()->setEnabled(true); + } + } else { + // Not a single object is selected. + myObjectName->setText(""); + buttonOk()->setEnabled(false); + buttonApply()->setEnabled(false); + } + + processPreview(); +} + +//================================================================================= +// function : SetEditCurrentArgument() +// purpose : +//================================================================================= +void TransformationGUI_ProjectionOnCylDlg::SetEditCurrentArgument() +{ + myObjectName->setFocus(); + myEditCurrentArgument = myObjectName; + SelectionIntoArgument(); +} + +//================================================================================= +// function : SetUseLengthAngle() +// purpose : +//================================================================================= +void TransformationGUI_ProjectionOnCylDlg::SetUseLengthAngle() +{ + myAngleLenSpin->setEnabled(myUseAngleLen->isChecked()); + processPreview(); +} + +//================================================================================= +// function : activateSelection +// purpose : activate selection of wires or faces +//================================================================================= +void TransformationGUI_ProjectionOnCylDlg::activateSelection() +{ + TColStd_MapOfInteger aMap; + + aMap.Add(GEOM_WIRE); + aMap.Add(GEOM_FACE); + globalSelection(aMap); +} + +//================================================================================= +// function : ActivateThisDialog() +// purpose : +//================================================================================= +void TransformationGUI_ProjectionOnCylDlg::ActivateThisDialog() +{ + GEOMBase_Skeleton::ActivateThisDialog(); + connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ), + this, SLOT( SelectionIntoArgument() ) ); + + activateSelection(); +} + +//================================================================================= +// function : enterEvent() +// purpose : +//================================================================================= +void TransformationGUI_ProjectionOnCylDlg::enterEvent (QEvent*) +{ + if (!mainFrame()->GroupConstructors->isEnabled()) + ActivateThisDialog(); +} + +//================================================================================= +// function : createOperation +// purpose : +//================================================================================= +GEOM::GEOM_IOperations_ptr TransformationGUI_ProjectionOnCylDlg::createOperation() +{ + return getGeomEngine()->GetITransformOperations(getStudyId()); +} + +//================================================================================= +// function : isValid +// purpose : +//================================================================================= +bool TransformationGUI_ProjectionOnCylDlg::isValid (QString &msg) +{ + bool isOk = false; + + if (!myObj->_is_nil() && + myRadiusSpin->isValid(msg, !IsPreview()) && + myStartAngleSpin->isValid(msg, !IsPreview())) { + if (myUseAngleLen->isChecked()) { + // Check length angle spin. + isOk = myAngleLenSpin->isValid(msg, !IsPreview()); + } else { + // Don't check length angle spin. + isOk = true; + } + } + + return isOk; +} + +//================================================================================= +// function : execute +// purpose : +//================================================================================= +bool TransformationGUI_ProjectionOnCylDlg::execute (ObjectList& objects) +{ + GEOM::GEOM_ITransformOperations_var anOper = + GEOM::GEOM_ITransformOperations::_narrow(getOperation()); + + double aRadius = myRadiusSpin->value(); + double aStartAngle = myStartAngleSpin->value()*M_PI/180.; + double aLengthAngle = -1.; + + if (myUseAngleLen->isChecked()) { + aLengthAngle = myAngleLenSpin->value()*M_PI/180.; + } + + GEOM::GEOM_Object_var anObj = anOper->MakeProjectionOnCylinder + (myObj, aRadius, aStartAngle, aLengthAngle); + + if (!anObj->_is_nil()) { + objects.push_back(anObj._retn()); + } + + return true; +} diff --git a/src/TransformationGUI/TransformationGUI_ProjectionOnCylDlg.h b/src/TransformationGUI/TransformationGUI_ProjectionOnCylDlg.h new file mode 100644 index 000000000..beb16d976 --- /dev/null +++ b/src/TransformationGUI/TransformationGUI_ProjectionOnCylDlg.h @@ -0,0 +1,78 @@ +// Copyright (C) 2007-2014 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 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 +// version 2.1 of the License, or (at your option) any later version. +// +// 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 +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +// GEOM GEOMGUI : GUI for Geometry component +// File : TransformationGUI_ProjectionOnCylDlg.h +// Author : Sergey KHROMOV, Open CASCADE S.A.S. +// +#ifndef TRANSFORMATIONGUI_PROJECTIONONCYLDLG_H +#define TRANSFORMATIONGUI_PROJECTIONONCYLDLG_H + + +#include "GEOMBase_Skeleton.h" + + +//================================================================================= +// class : TransformationGUI_ProjectionOnCylDlg +// purpose : +//================================================================================= +class TransformationGUI_ProjectionOnCylDlg : public GEOMBase_Skeleton +{ + Q_OBJECT + +public: + TransformationGUI_ProjectionOnCylDlg(GeometryGUI*, QWidget* = 0, + bool = false, Qt::WindowFlags = 0); + ~TransformationGUI_ProjectionOnCylDlg(); + +protected: + // redefined from GEOMBase_Helper + virtual GEOM::GEOM_IOperations_ptr createOperation(); + virtual bool isValid(QString &msg); + virtual bool execute(ObjectList &); + +private: + void Init(); + void enterEvent( QEvent* ); + void activateSelection(); + +private slots: + void ClickOnOk(); + bool ClickOnApply(); + void ActivateThisDialog(); + void SelectionIntoArgument(); + void SetEditCurrentArgument(); + void SetUseLengthAngle(); + +private: + + GEOM::GEOM_Object_var myObj; + QLineEdit *myObjectName; + QPushButton *mySelButton; + SalomeApp_DoubleSpinBox *myRadiusSpin; + SalomeApp_DoubleSpinBox *myStartAngleSpin; + QCheckBox *myUseAngleLen; + SalomeApp_DoubleSpinBox *myAngleLenSpin; + +}; + +#endif // TRANSFORMATIONGUI_PROJECTIONONCYLDLG_H