From: eap Date: Mon, 20 Jun 2005 05:04:40 +0000 (+0000) Subject: PAL9166. Add possibility to make sketcher on an existing plane X-Git-Tag: V2_2_4~2 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=eab0044eba5ef91ac66f6692d6a41600091b5674;p=modules%2Fgeom.git PAL9166. Add possibility to make sketcher on an existing plane --- diff --git a/src/GEOMImpl/GEOMImpl_ICurvesOperations.cxx b/src/GEOMImpl/GEOMImpl_ICurvesOperations.cxx index 2bf1dfc6e..e80e61c79 100644 --- a/src/GEOMImpl/GEOMImpl_ICurvesOperations.cxx +++ b/src/GEOMImpl/GEOMImpl_ICurvesOperations.cxx @@ -543,7 +543,7 @@ Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeSketcher (const char* theCom //Add a new Sketcher function Handle(GEOM_Function) aFunction = - aSketcher->AddFunction(GEOMImpl_SketcherDriver::GetID(), SKETCHER_COMMAND); + aSketcher->AddFunction(GEOMImpl_SketcherDriver::GetID(), SKETCHER_NINE_DOUBLS); if (aFunction.IsNull()) return NULL; //Check if the function is set correctly @@ -594,3 +594,65 @@ Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeSketcher (const char* theCom SetErrorCode(OK); return aSketcher; } + + +//============================================================================= +/*! + * MakeSketcherOnPlane + */ +//============================================================================= +Handle(GEOM_Object) GEOMImpl_ICurvesOperations::MakeSketcherOnPlane (const char* theCommand, + Handle(GEOM_Object) theWorkingPlane) +{ + SetErrorCode(KO); + + if (!theCommand) return NULL; + if (strcmp(theCommand, "") == 0) return NULL; + + //Add a new Sketcher object + Handle(GEOM_Object) aSketcher = GetEngine()->AddObject(GetDocID(), GEOM_SKETCHER); + + //Add a new Sketcher function + Handle(GEOM_Function) aFunction = + aSketcher->AddFunction(GEOMImpl_SketcherDriver::GetID(), SKETCHER_PLANE); + if (aFunction.IsNull()) return NULL; + + //Check if the function is set correctly + if (aFunction->GetDriverGUID() != GEOMImpl_SketcherDriver::GetID()) return NULL; + + GEOMImpl_ISketcher aCI (aFunction); + + TCollection_AsciiString aCommand ((char*) theCommand); + aCI.SetCommand(aCommand); + + Handle(GEOM_Function) aRefPlane = theWorkingPlane->GetLastFunction(); + if (aRefPlane.IsNull()) return NULL; + aCI.SetWorkingPlane( aRefPlane ); + + //Compute the Sketcher value + try { + if (!GetSolver()->ComputeFunction(aFunction)) { + SetErrorCode("Sketcher driver failed"); + return NULL; + } + } + catch (Standard_Failure) { + Handle(Standard_Failure) aFail = Standard_Failure::Caught(); + SetErrorCode(aFail->GetMessageString()); + return NULL; + } + + //Make a Python command + TCollection_AsciiString anEntry, aDescr; + TDF_Tool::Entry(aSketcher->GetEntry(), anEntry); + aDescr += anEntry; + aDescr += " = ICurvesOperations.MakeSketcherOnPlane("; + aDescr += aCommand+", "; + TDF_Tool::Entry(theWorkingPlane->GetEntry(), anEntry); + aDescr += anEntry + " )"; + + aFunction->SetDescription(aDescr); + + SetErrorCode(OK); + return aSketcher; +} diff --git a/src/GEOMImpl/GEOMImpl_ICurvesOperations.hxx b/src/GEOMImpl/GEOMImpl_ICurvesOperations.hxx index 0c52cc7ec..e421f642e 100644 --- a/src/GEOMImpl/GEOMImpl_ICurvesOperations.hxx +++ b/src/GEOMImpl/GEOMImpl_ICurvesOperations.hxx @@ -35,6 +35,8 @@ class GEOMImpl_ICurvesOperations : public GEOM_IOperations { Handle(GEOM_Object) MakeSplineInterpolation (list thePoints); Handle(GEOM_Object) MakeSketcher (const char* theCommand, list theWorkingPlane); + Handle(GEOM_Object) MakeSketcherOnPlane (const char* theCommand, + Handle(GEOM_Object) theWorkingPlane); }; #endif diff --git a/src/GEOMImpl/GEOMImpl_ISketcher.hxx b/src/GEOMImpl/GEOMImpl_ISketcher.hxx index 74912ff38..b32dab4d6 100644 --- a/src/GEOMImpl/GEOMImpl_ISketcher.hxx +++ b/src/GEOMImpl/GEOMImpl_ISketcher.hxx @@ -4,7 +4,8 @@ #include "GEOM_Function.hxx" #define SKETCH_ARG_CMD 1 -#define SKETCH_ARG_WPLANE 2 +#define SKETCH_ARG_DOUBLE 2 +#define SKETCH_ARG_WPLANE 12 class GEOMImpl_ISketcher { @@ -18,9 +19,14 @@ class GEOMImpl_ISketcher TCollection_AsciiString GetCommand() { return _func->GetString(SKETCH_ARG_CMD); } void SetWorkingPlane(int theInd, double theValue) - { _func->SetReal(SKETCH_ARG_WPLANE + theInd, theValue); } + { _func->SetReal(SKETCH_ARG_DOUBLE + theInd, theValue); } - double GetWorkingPlane(int theInd) { return _func->GetReal(SKETCH_ARG_WPLANE + theInd); } + double GetWorkingPlane(int theInd) { return _func->GetReal(SKETCH_ARG_DOUBLE + theInd); } + + void SetWorkingPlane(Handle(GEOM_Function) thePlane) + { _func->SetReference(SKETCH_ARG_WPLANE, thePlane); } + + Handle(GEOM_Function) GetWorkingPlane() { return _func->GetReference(SKETCH_ARG_WPLANE); } private: diff --git a/src/GEOMImpl/GEOMImpl_SketcherDriver.cxx b/src/GEOMImpl/GEOMImpl_SketcherDriver.cxx index 0b79130b2..b0822626a 100644 --- a/src/GEOMImpl/GEOMImpl_SketcherDriver.cxx +++ b/src/GEOMImpl/GEOMImpl_SketcherDriver.cxx @@ -5,10 +5,12 @@ using namespace std; #include "GEOMImpl_Types.hxx" #include "GEOM_Function.hxx" -#include -#include -#include #include +#include +#include +#include +#include +#include #include @@ -63,12 +65,30 @@ Standard_Integer GEOMImpl_SketcherDriver::Execute(TFunction_Logbook& log) const if (aShape.IsNull()) return 0; + gp_Ax3 aWPlane; + if ( aFunction->GetType() == SKETCHER_NINE_DOUBLS ) + { + gp_Pnt aOrigin = + gp_Pnt(aCI.GetWorkingPlane(1), aCI.GetWorkingPlane(2), aCI.GetWorkingPlane(3)); + gp_Dir aDirZ = + gp_Dir(aCI.GetWorkingPlane(4), aCI.GetWorkingPlane(5), aCI.GetWorkingPlane(6)); + gp_Dir aDirX = + gp_Dir(aCI.GetWorkingPlane(7), aCI.GetWorkingPlane(8), aCI.GetWorkingPlane(9)); + aWPlane = gp_Ax3(aOrigin, aDirZ, aDirX); + } + else + { + Handle(GEOM_Function) aRefFace = aCI.GetWorkingPlane(); + TopoDS_Shape aShape = aRefFace->GetValue(); + if ( aShape.IsNull() || aShape.ShapeType() != TopAbs_FACE ) + return 0; + Handle(Geom_Surface) aGS = BRep_Tool::Surface( TopoDS::Face( aShape )); + if ( aGS.IsNull() || !aGS->IsKind( STANDARD_TYPE( Geom_Plane ))) + return 0; + Handle(Geom_Plane) aGPlane = Handle(Geom_Plane)::DownCast( aGS ); + aWPlane = aGPlane->Pln().Position(); + } gp_Trsf aTrans; - gp_Pnt aOrigin = gp_Pnt(aCI.GetWorkingPlane(1), aCI.GetWorkingPlane(2), aCI.GetWorkingPlane(3)); - gp_Dir aDirZ = gp_Dir(aCI.GetWorkingPlane(4), aCI.GetWorkingPlane(5), aCI.GetWorkingPlane(6)); - gp_Dir aDirX = gp_Dir(aCI.GetWorkingPlane(7), aCI.GetWorkingPlane(8), aCI.GetWorkingPlane(9)); - gp_Ax3 aWPlane = gp_Ax3(aOrigin, aDirZ, aDirX); - aTrans.SetTransformation(aWPlane); aTrans.Invert(); BRepBuilderAPI_Transform aTransformation (aShape, aTrans, Standard_False); diff --git a/src/GEOMImpl/GEOMImpl_Types.hxx b/src/GEOMImpl/GEOMImpl_Types.hxx index 982ef59ae..d3ede4bd5 100755 --- a/src/GEOMImpl/GEOMImpl_Types.hxx +++ b/src/GEOMImpl/GEOMImpl_Types.hxx @@ -188,7 +188,8 @@ #define GLUE_FACES 1 -#define SKETCHER_COMMAND 1 +#define SKETCHER_NINE_DOUBLS 1 +#define SKETCHER_PLANE 2 #define CDG_MEASURE 1