From b5c1f9a735cafe5c142a3f28f8b03b88b1cbba30 Mon Sep 17 00:00:00 2001 From: jfa Date: Fri, 22 Apr 2011 11:47:35 +0000 Subject: [PATCH] IMP 0021068 (Projection) and bug 0021110 (Low efficiency of the explode) --- idl/GEOM_Gen.idl | 26 +- resources/Makefile.am | 1 + resources/projection.png | Bin 0 -> 792 bytes src/EntityGUI/EntityGUI_SubShapeDlg.cxx | 36 +-- src/GEOMGUI/GEOMGUI.cxx | 4 +- src/GEOMGUI/GEOM_images.ts | 8 + src/GEOMGUI/GEOM_msg_en.ts | 28 ++ src/GEOMGUI/GeometryGUI.cxx | 4 + src/GEOMGUI/GeometryGUI_Operations.h | 1 + src/GEOMImpl/GEOMImpl_IMirror.hxx | 5 +- src/GEOMImpl/GEOMImpl_IShapesOperations.cxx | 83 ++++++ src/GEOMImpl/GEOMImpl_IShapesOperations.hxx | 4 + .../GEOMImpl_ITransformOperations.cxx | 54 ++++ .../GEOMImpl_ITransformOperations.hxx | 3 + src/GEOMImpl/GEOMImpl_MirrorDriver.cxx | 135 ++++++++- src/GEOMImpl/GEOMImpl_Types.hxx | 4 + src/GEOM_I/GEOM_Gen_i.cc | 6 +- src/GEOM_I/GEOM_IShapesOperations_i.cc | 46 ++- src/GEOM_I/GEOM_IShapesOperations_i.hh | 3 + src/GEOM_I/GEOM_ITransformOperations_i.cc | 27 ++ src/GEOM_I/GEOM_ITransformOperations_i.hh | 3 + src/GEOM_SWIG/geompyDC.py | 24 ++ src/TransformationGUI/Makefile.am | 9 +- src/TransformationGUI/TransformationGUI.cxx | 7 +- .../TransformationGUI_ProjectionDlg.cxx | 277 ++++++++++++++++++ .../TransformationGUI_ProjectionDlg.h | 70 +++++ 26 files changed, 817 insertions(+), 51 deletions(-) create mode 100644 resources/projection.png create mode 100644 src/TransformationGUI/TransformationGUI_ProjectionDlg.cxx create mode 100644 src/TransformationGUI/TransformationGUI_ProjectionDlg.h diff --git a/idl/GEOM_Gen.idl b/idl/GEOM_Gen.idl index 05e030217..6c95eef1b 100644 --- a/idl/GEOM_Gen.idl +++ b/idl/GEOM_Gen.idl @@ -906,6 +906,14 @@ module GEOM */ GEOM_Object OffsetShapeCopy (in GEOM_Object theObject, in double theOffset); + /*! + * Create new object as projection of the given one on a 2D surface. + * \param theSource The source object for the projection. It can be a point, edge or wire. + * \param theTarget The target object. It can be planar or cylindrical face. + * \return New GEOM_Object, containing the projection. + */ + GEOM_Object ProjectShapeCopy (in GEOM_Object theSource, in GEOM_Object theTarget); + /*! * Scale the given object by the factor. * \param theObject The object to be scaled. @@ -1558,12 +1566,26 @@ module GEOM /*! * Get a sub shape defined by its unique ID inside \a theMainShape + * \param theMainShape Main shape. + * \param theID Unique ID of sub shape inside \a theMainShape. + * \return GEOM_Object, corresponding to found sub shape. * \note The sub shape GEOM_Objects can has ONLY ONE function. - * Don't try to apply modification operations on them. + * Don't try to apply modification operations (without copy) on them. */ GEOM_Object GetSubShape (in GEOM_Object theMainShape, in long theID); + /*! + * Get a set of sub shapes defined by their unique IDs inside \a theMainShape + * \param theMainShape Main shape. + * \param theIndices List of unique IDs of sub shapes inside \a theMainShape. + * \return List of GEOM_Objects, corresponding to found sub shapes. + * \note The sub shape GEOM_Objects can has ONLY ONE function. + * Don't try to apply modification operations (without copy) on them. + */ + ListOfGO MakeSubShapes (in GEOM_Object theMainShape, + in ListOfLong theIndices); + /*! * Get global index of \a theSubShape in \a theMainShape. * \param theMainShape Main shape. @@ -3625,7 +3647,7 @@ module GEOM /*! * Add a sub shape defined by indices in \a theIndices - * (contains unique IDs of sub shapes inside theMainShape) + * (contains unique IDs of sub shapes inside \a theMainShape) * \note The sub shape GEOM_Objects can has ONLY ONE function. * Don't try to apply modification operations on them. * \note Internal method diff --git a/resources/Makefile.am b/resources/Makefile.am index 57529e357..f6c3048be 100644 --- a/resources/Makefile.am +++ b/resources/Makefile.am @@ -112,6 +112,7 @@ multitranslationdouble.png \ multitranslationsimple.png \ normale.png \ offset.png \ +projection.png \ origin_and_vectors.png \ partition.png \ partitionkeep.png \ diff --git a/resources/projection.png b/resources/projection.png new file mode 100644 index 0000000000000000000000000000000000000000..6b22c1dc773ccd140019cc917f06514b058ba5c8 GIT binary patch literal 792 zcmV+z1LypSP)Tlih0-M;wNqJsyeRAE3F`D={=!qw#~29?+Q3f>4Tz zy$}k1AQVAGgjOp=L8W2~Qm`WRqD7IY*cLPeK|zS%O|ozEpTXXa4__49>M#7m4I==o!@ql zWf@abQ^~u4uMH#cC~#q5U|@3Dw*MG zoWqI7SV0*f)s8>*4RG!7dRn<*#qPgY^Zmu>LFi0*x^j1i`uh69XIoEVtjCI=t>@1J zO@@BFfz}4eT8PQ<-j(}@s)ht;SL^`Dv_m@~*Fvg_jVepA*~?<)Gu%779pK-$fE_`c z>F@6k%eS2dKpR0>;o9N#e6e>FtJ+xA!m1YcFYE!h9Wm{C>>Cx>UEpc0R>OM;A>hO_ zZ|eCG^W_Y~BLk z!R4PyyXm-hq8>q%utuX1mTo$RHbQQM+&Hp$cTUINCp8GZYBw2YngI0l^n`l72>kPH zzhaz6+aiQaJ8m8SlGVG;<5UZ$Qp74AUKuIvCMo`=yFgm+?(Pmtw*Ep0#eF?*>7sL1 za7J_c)Yq)q@jEV`!Rf51iP%}~ViwHr>gsBX2#x*M@#0W3&loSNz{>B=AXddN6kaTk z{ysUYT?t%35zG*<1)zWDIlR?)XAr9qtMJa?#q#){pG#Off<}QSrE)^?5BJ7!76S`` zuK;>Ck04g_|J9>ZMhTk$ZpLR?1rnhPBe1s<%$wqt_ckl63M|LFz)*CpO{H_4Fo0Ld Wi=bn&Fz%E90000ExtractSubShapes(myObject, shapeType(), true); - GEOM::ListOfGO_var aList = anOper->ExtractSubShapes(myObject, shapeType(), isAllSubShapes()); - if (!aList->length()) - return false; - - // Throw away sub-shapes not selected by user if not in preview mode - // and manual selection is active if (!isAllSubShapes()) { + // manual selection TColStd_IndexedMapOfInteger aMapIndex; int nbSel = getSelectedSubshapes(aMapIndex); if (nbSel > 0) { - //GEOM::GEOM_ILocalOperations_var aLocOp = - // getGeomEngine()->GetILocalOperations(getStudyId()); - TopTools_IndexedMapOfShape aSubShapesMap; - TopExp::MapShapes(myShape, aSubShapesMap); - - for (int i = 0, n = aList->length(); i < n; i++) { - //if (aMapIndex.Contains(aLocOp->GetSubShapeIndex(myObject, aList[i]))) - TopoDS_Shape aSShape = GEOM_Client::get_client().GetShape(GeometryGUI::GetGeomGen(), aList[i]); - if (aMapIndex.Contains(aSubShapesMap.FindIndex(aSShape))) - objects.push_back(GEOM::GEOM_Object::_duplicate(aList[i])); - else - aList[i]->UnRegister(); - } + int i; + + GEOM::ListOfLong_var anArray = new GEOM::ListOfLong; + anArray->length(nbSel); + + for (i = 1; i <= nbSel; i++) + anArray[i - 1] = aMapIndex.FindKey(i); + + GEOM::ListOfGO_var aList = anOper->MakeSubShapes(myObject, anArray); + int n = aList->length(); + for (i = 0; i < n; i++) + objects.push_back(GEOM::GEOM_Object::_duplicate(aList[i])); } } else { + GEOM::ListOfGO_var aList = anOper->ExtractSubShapes(myObject, shapeType(), true); + if (!aList->length()) + return false; for (int i = 0, n = aList->length(); i < n; i++) objects.push_back(GEOM::GEOM_Object::_duplicate(aList[i])); } diff --git a/src/GEOMGUI/GEOMGUI.cxx b/src/GEOMGUI/GEOMGUI.cxx index b93fbb516..9bb0e521a 100644 --- a/src/GEOMGUI/GEOMGUI.cxx +++ b/src/GEOMGUI/GEOMGUI.cxx @@ -18,12 +18,11 @@ // 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 : GEOMGUI.cxx // Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com) -// + #include "GEOMGUI.h" #include "GeometryGUI.h" @@ -109,4 +108,3 @@ GeometryGUI* GEOMGUI::getGeometryGUI() { return myGeometryGUI; } - diff --git a/src/GEOMGUI/GEOM_images.ts b/src/GEOMGUI/GEOM_images.ts index 3051bf90c..7c77b2a38 100644 --- a/src/GEOMGUI/GEOM_images.ts +++ b/src/GEOMGUI/GEOM_images.ts @@ -341,6 +341,10 @@ ICON_DLG_OFFSET offset.png + + ICON_DLG_PROJECTION + projection.png + ICON_DLG_PARTITION partition.png @@ -921,6 +925,10 @@ ICO_OFFSET offset.png + + ICO_PROJECTION + projection.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 8080afbbd..7ecca0612 100644 --- a/src/GEOMGUI/GEOM_msg_en.ts +++ b/src/GEOMGUI/GEOM_msg_en.ts @@ -1065,6 +1065,22 @@ Please, select face, shell or solid and try again GEOM_OFFSET_TITLE Offset Surface + + GEOM_PROJECTION + Projection + + + GEOM_PROJECTION_TITLE + Projection on Face + + + GEOM_SOURCE_OBJECT + Source vertex, edge or wire + + + GEOM_TARGET_OBJECT + Target face + GEOM_OPERATIONS Operations @@ -2425,6 +2441,10 @@ Please, select face, shell or solid and try again MEN_OFFSET Offset Surface + + MEN_PROJECTION + Projection + MEN_OPERATIONS Operations @@ -3077,6 +3097,10 @@ Please, select face, shell or solid and try again STB_OFFSET Offset surface + + STB_PROJECTION + Project a point, an edge or a wire on a face + STB_ORIGIN_AND_VECTORS Create an origin and base Vectors @@ -3613,6 +3637,10 @@ Please, select face, shell or solid and try again TOP_OFFSET Offset surface + + TOP_PROJECTION + Projection + TOP_ORIGIN_AND_VECTORS Create an origin and base Vectors diff --git a/src/GEOMGUI/GeometryGUI.cxx b/src/GEOMGUI/GeometryGUI.cxx index 4d86bb486..6adc5773a 100644 --- a/src/GEOMGUI/GeometryGUI.cxx +++ b/src/GEOMGUI/GeometryGUI.cxx @@ -468,6 +468,7 @@ void GeometryGUI::OnGUIEvent( int id ) case GEOMOp::OpMirror: // MENU TRANSFORMATION - MIRROR case GEOMOp::OpScale: // MENU TRANSFORMATION - SCALE case GEOMOp::OpOffset: // MENU TRANSFORMATION - OFFSET + case GEOMOp::OpProjection: // MENU TRANSFORMATION - PROJECTION case GEOMOp::OpMultiTranslate: // MENU TRANSFORMATION - MULTI-TRANSLATION case GEOMOp::OpMultiRotate: // MENU TRANSFORMATION - MULTI-ROTATION case GEOMOp::OpReimport: // CONTEXT(POPUP) MENU - RELOAD_IMPORTED @@ -710,6 +711,7 @@ void GeometryGUI::initialize( CAM_Application* app ) createGeomAction( GEOMOp::OpMirror, "MIRROR" ); createGeomAction( GEOMOp::OpScale, "SCALE" ); createGeomAction( GEOMOp::OpOffset, "OFFSET" ); + createGeomAction( GEOMOp::OpProjection, "PROJECTION" ); createGeomAction( GEOMOp::OpMultiTranslate, "MUL_TRANSLATION" ); createGeomAction( GEOMOp::OpMultiRotate, "MUL_ROTATION" ); @@ -898,6 +900,7 @@ void GeometryGUI::initialize( CAM_Application* app ) createMenu( GEOMOp::OpMirror, transId, -1 ); createMenu( GEOMOp::OpScale, transId, -1 ); createMenu( GEOMOp::OpOffset, transId, -1 ); + createMenu( GEOMOp::OpProjection, transId, -1 ); createMenu( separator(), transId, -1 ); createMenu( GEOMOp::OpMultiTranslate, transId, -1 ); createMenu( GEOMOp::OpMultiRotate, transId, -1 ); @@ -1034,6 +1037,7 @@ void GeometryGUI::initialize( CAM_Application* app ) createTool( GEOMOp::OpMirror, transTbId ); createTool( GEOMOp::OpScale, transTbId ); createTool( GEOMOp::OpOffset, transTbId ); + createTool( GEOMOp::OpProjection, 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 24da14bed..7f0cabbfd 100644 --- a/src/GEOMGUI/GeometryGUI_Operations.h +++ b/src/GEOMGUI/GeometryGUI_Operations.h @@ -114,6 +114,7 @@ namespace GEOMOp { OpMultiTranslate = 3606, // MENU OPERATIONS - TRANSFORMATION - MULTI-TRANSLATION OpMultiRotate = 3607, // MENU OPERATIONS - TRANSFORMATION - MULTI-ROTATION OpReimport = 3608, // POPUP MENU - RELOAD IMPORTED + OpProjection = 3609, // MENU OPERATIONS - TRANSFORMATION - PROJECTION // OperationGUI OpPartition = 3700, // MENU OPERATION - PARTITION OpArchimede = 3701, // MENU OPERATION - ARCHIMEDE diff --git a/src/GEOMImpl/GEOMImpl_IMirror.hxx b/src/GEOMImpl/GEOMImpl_IMirror.hxx index 3442707a2..7fb679459 100644 --- a/src/GEOMImpl/GEOMImpl_IMirror.hxx +++ b/src/GEOMImpl/GEOMImpl_IMirror.hxx @@ -18,10 +18,9 @@ // 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 intreface to a function for the Mirror creation. -// +//NOTE: This is an interface to a function for the Mirror creation. + #include "GEOM_Function.hxx" #define MIRROR_ARG_ORIGINAL 1 diff --git a/src/GEOMImpl/GEOMImpl_IShapesOperations.cxx b/src/GEOMImpl/GEOMImpl_IShapesOperations.cxx index 6c126293a..53b8a4629 100644 --- a/src/GEOMImpl/GEOMImpl_IShapesOperations.cxx +++ b/src/GEOMImpl/GEOMImpl_IShapesOperations.cxx @@ -1196,6 +1196,89 @@ Handle(GEOM_Object) GEOMImpl_IShapesOperations::GetSubShape return anObj; } +//============================================================================= +/*! + * MakeSubShapes + */ +//============================================================================= +Handle(TColStd_HSequenceOfTransient) GEOMImpl_IShapesOperations::MakeSubShapes + (Handle(GEOM_Object) theMainShape, + Handle(TColStd_HArray1OfInteger) theIndices) +{ + SetErrorCode(KO); + + Handle(TColStd_HSequenceOfTransient) aSeq = new TColStd_HSequenceOfTransient; + + if (!theIndices->Length()) { + SetErrorCode(NOT_FOUND_ANY); + return aSeq; + } + + if (theMainShape.IsNull()) return NULL; + TopoDS_Shape aShape = theMainShape->GetValue(); + if (aShape.IsNull()) return NULL; + + Handle(GEOM_Function) aMainShape = theMainShape->GetLastFunction(); + + TopTools_IndexedMapOfShape anIndices; + TopExp::MapShapes(aShape, anIndices); + + Handle(TColStd_HArray1OfInteger) anArray; + Handle(GEOM_Object) anObj; + + TCollection_AsciiString anAsciiList, anEntry; + Standard_Integer i, low = theIndices->Lower(), up = theIndices->Upper(); + for (i = low; i <= up; i++) { + int id = theIndices->Value(i); + if (1 <= id && id <= anIndices.Extent()) { + TopoDS_Shape aValue = anIndices.FindKey(id); + anArray = new TColStd_HArray1OfInteger(1,1); + anArray->SetValue(1, id); + + anObj = GetEngine()->AddObject(GetDocID(), GEOM_SUBSHAPE); + if (!anObj.IsNull()) { + Handle(GEOM_Function) aFunction = anObj->AddFunction(GEOM_Object::GetSubShapeID(), 1); + if (aFunction.IsNull()) return aSeq; + + GEOM_ISubShape aSSI (aFunction); + aSSI.SetMainShape(aMainShape); + aSSI.SetIndices(anArray); + + // Set function value directly, as we know it. + // Usage of Solver here would lead to significant loss of time, + // because GEOM_SubShapeDriver will build TopTools_IndexedMapOfShape + // on the main shape for each being calculated sub-shape separately. + aFunction->SetValue(aValue); + + // Put this subshape in the list of subshapes of theMainShape + aMainShape->AddSubShapeReference(aFunction); + + aSeq->Append(anObj); + + // for python command + TDF_Tool::Entry(anObj->GetEntry(), anEntry); + anAsciiList += anEntry; + anAsciiList += ","; + } + } + } + + //Make a Python command + anAsciiList.Trunc(anAsciiList.Length() - 1); + + GEOM::TPythonDump pd (aMainShape, /*append=*/true); + pd << "[" << anAsciiList.ToCString() << "] = geompy.SubShapes(" + << theMainShape << ", [" ; + for (i = low; i <= up - 1; i++) { + pd << theIndices->Value(i) << ", "; + } + pd << theIndices->Value(up) << "])"; + + SetErrorCode(OK); + + return aSeq; +} + //============================================================================= /*! * GetSubShapeIndex diff --git a/src/GEOMImpl/GEOMImpl_IShapesOperations.hxx b/src/GEOMImpl/GEOMImpl_IShapesOperations.hxx index f9c672618..0c8c33e87 100644 --- a/src/GEOMImpl/GEOMImpl_IShapesOperations.hxx +++ b/src/GEOMImpl/GEOMImpl_IShapesOperations.hxx @@ -123,6 +123,10 @@ class GEOMImpl_IShapesOperations : public GEOM_IOperations Standard_EXPORT Handle(GEOM_Object) GetSubShape (Handle(GEOM_Object) theMainShape, const Standard_Integer theID); + Standard_EXPORT Handle(TColStd_HSequenceOfTransient) MakeSubShapes + (Handle(GEOM_Object) theMainShape, + Handle(TColStd_HArray1OfInteger) theIndices); + Standard_EXPORT Standard_Integer GetSubShapeIndex (Handle(GEOM_Object) theMainShape, Handle(GEOM_Object) theSubShape); diff --git a/src/GEOMImpl/GEOMImpl_ITransformOperations.cxx b/src/GEOMImpl/GEOMImpl_ITransformOperations.cxx index b5731bfc1..5613f1d03 100644 --- a/src/GEOMImpl/GEOMImpl_ITransformOperations.cxx +++ b/src/GEOMImpl/GEOMImpl_ITransformOperations.cxx @@ -1176,6 +1176,60 @@ Handle(GEOM_Object) GEOMImpl_ITransformOperations::OffsetShapeCopy } +//============================================================================= +/*! + * ProjectShapeCopy + */ +//============================================================================= +Handle(GEOM_Object) GEOMImpl_ITransformOperations::ProjectShapeCopy + (Handle(GEOM_Object) theSource, Handle(GEOM_Object) theTarget) +{ + SetErrorCode(KO); + + if (theSource.IsNull() || theTarget.IsNull()) return NULL; + + Handle(GEOM_Function) aLastFunction = theSource->GetLastFunction(); + if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be projected + + //Add a new Projection object + Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), GEOM_PROJECTION); + + //Add a Projection function + Handle(GEOM_Function) aFunction = + aCopy->AddFunction(GEOMImpl_MirrorDriver::GetID(), PROJECTION_COPY); + + //Check if the function is set correctly + if (aFunction->GetDriverGUID() != GEOMImpl_MirrorDriver::GetID()) return NULL; + + GEOMImpl_IMirror aTI (aFunction); + aTI.SetPlane(theTarget->GetLastFunction()); + aTI.SetOriginal(aLastFunction); + + //Compute the Projection + try { +#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100 + OCC_CATCH_SIGNALS; +#endif + if (!GetSolver()->ComputeFunction(aFunction)) { + SetErrorCode("Projection driver failed"); + return NULL; + } + } + catch (Standard_Failure) { + Handle(Standard_Failure) aFail = Standard_Failure::Caught(); + SetErrorCode(aFail->GetMessageString()); + return NULL; + } + + //Make a Python command + GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MakeProjection(" + << theSource << ", " << theTarget << ")"; + + SetErrorCode(OK); + return aCopy; +} + + //============================================================================= /*! * ScaleShape diff --git a/src/GEOMImpl/GEOMImpl_ITransformOperations.hxx b/src/GEOMImpl/GEOMImpl_ITransformOperations.hxx index bdac1b1bd..3837fb447 100644 --- a/src/GEOMImpl/GEOMImpl_ITransformOperations.hxx +++ b/src/GEOMImpl/GEOMImpl_ITransformOperations.hxx @@ -109,6 +109,9 @@ class GEOMImpl_ITransformOperations : public GEOM_IOperations Standard_EXPORT Handle(GEOM_Object) OffsetShapeCopy (Handle(GEOM_Object) theObject, double theOffset); + Standard_EXPORT Handle(GEOM_Object) ProjectShapeCopy (Handle(GEOM_Object) theSource, + Handle(GEOM_Object) theTarget); + Standard_EXPORT Handle(GEOM_Object) ScaleShape (Handle(GEOM_Object) theObject, Handle(GEOM_Object) thePoint, double theFactor); diff --git a/src/GEOMImpl/GEOMImpl_MirrorDriver.cxx b/src/GEOMImpl/GEOMImpl_MirrorDriver.cxx index 15e642cbe..074ca7788 100644 --- a/src/GEOMImpl/GEOMImpl_MirrorDriver.cxx +++ b/src/GEOMImpl/GEOMImpl_MirrorDriver.cxx @@ -18,7 +18,6 @@ // 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 @@ -30,6 +29,10 @@ #include #include +#include +#include +#include +#include #include #include @@ -40,6 +43,7 @@ #include #include +#include #include #include @@ -89,6 +93,120 @@ Standard_Integer GEOMImpl_MirrorDriver::Execute(TFunction_Logbook& log) const TopoDS_Shape anOriginal = anOriginalFunction->GetValue(); if (anOriginal.IsNull()) return 0; + // Projection + if (aType == PROJECTION_COPY) { + // Source shape (point, edge or wire) + if (anOriginal.ShapeType() != TopAbs_VERTEX && + anOriginal.ShapeType() != TopAbs_EDGE && + anOriginal.ShapeType() != TopAbs_WIRE) { + Standard_ConstructionError::Raise + ("Projection aborted : the source shape is neither a vertex, nor an edge or a wire"); + } + + // Target face + Handle(GEOM_Function) aTargetFunction = TI.GetPlane(); + if (aTargetFunction.IsNull()) return 0; + TopoDS_Shape aFaceShape = aTargetFunction->GetValue(); + //if (aFaceShape.IsNull() || aFaceShape.ShapeType() != TopAbs_FACE) { + // Standard_ConstructionError::Raise + // ("Projection aborted : the target shape is not a face"); + //} + + Standard_Real tol = 1.e-4; + + if (anOriginal.ShapeType() == TopAbs_VERTEX) { + if (aFaceShape.IsNull() || aFaceShape.ShapeType() != TopAbs_FACE) { + Standard_ConstructionError::Raise + ("Projection aborted : the target shape is not a face"); + } + TopoDS_Face aFace = TopoDS::Face(aFaceShape); + Handle(Geom_Surface) surface = BRep_Tool::Surface(aFace); + double U1, U2, V1, V2; + //surface->Bounds(U1, U2, V1, V2); + BRepTools::UVBounds(aFace, U1, U2, V1, V2); + + // projector + GeomAPI_ProjectPointOnSurf proj; + proj.Init(surface, U1, U2, V1, V2, tol); + + gp_Pnt aPnt = BRep_Tool::Pnt(TopoDS::Vertex(anOriginal)); + proj.Perform(aPnt); + if (!proj.IsDone()) { + Standard_ConstructionError::Raise + ("Projection aborted : GeomAPI_ProjectPointOnSurf failed"); + } + int nbPoints = proj.NbPoints(); + if (nbPoints < 1) { + Standard_ConstructionError::Raise("No solution found"); + } + + Quantity_Parameter U, V; + proj.LowerDistanceParameters(U, V); + gp_Pnt2d aProjPnt (U, V); + + // classifier + BRepClass_FaceClassifier aClsf (aFace, aProjPnt, tol); + if (aClsf.State() != TopAbs_IN && aClsf.State() != TopAbs_ON) { + bool isSol = false; + double minDist = RealLast(); + for (int i = 1; i <= nbPoints; i++) { + Quantity_Parameter Ui, Vi; + proj.Parameters(i, Ui, Vi); + aProjPnt = gp_Pnt2d(Ui, Vi); + aClsf.Perform(aFace, aProjPnt, tol); + if (aClsf.State() == TopAbs_IN || aClsf.State() == TopAbs_ON) { + isSol = true; + double dist = proj.Distance(i); + if (dist < minDist) { + minDist = dist; + U = Ui; + V = Vi; + } + } + } + if (!isSol) { + Standard_ConstructionError::Raise("No solution found"); + } + } + + gp_Pnt surfPnt = surface->Value(U, V); + + aShape = BRepBuilderAPI_MakeVertex(surfPnt).Shape(); + } + else { + //see BRepTest_BasicCommands.cxx for example of BRepOffsetAPI_NormalProjection + BRepOffsetAPI_NormalProjection OrtProj (aFaceShape); + OrtProj.Add(anOriginal); + + //Standard_Real tol = 1.e-4; + //Standard_Real tol2d = Pow(tol, 2./3); + //GeomAbs_Shape Continuity = GeomAbs_C2; + //Standard_Integer MaxDeg = 14; + //Standard_Integer MaxSeg = 16; + //OrtProj.SetParams(tol, tol2d, Continuity, MaxDeg, MaxSeg); + try { + OrtProj.Build(); + } catch (Standard_Failure) { + Handle(Standard_Failure) aFail = Standard_Failure::Caught(); + TCollection_AsciiString aMsg (aFail->GetMessageString()); + if (!aMsg.Length()) + aMsg = "Projection aborted : possibly the source shape intersects the cylinder's axis"; + Standard_ConstructionError::Raise(aMsg.ToCString()); + } + if (!OrtProj.IsDone()) { + Standard_ConstructionError::Raise + ("Projection aborted : BRepOffsetAPI_NormalProjection failed"); + } + + aShape = OrtProj.Shape(); + } + + if (aShape.IsNull()) return 0; + aFunction->SetValue(aShape); + log.SetTouched(Label()); + return 1; + } + // Bug 12158: Check for standalone (not included in faces) degenerated edges TopTools_IndexedDataMapOfShapeListOfShape aEFMap; TopExp::MapShapesAndAncestors(anOriginal, TopAbs_EDGE, TopAbs_FACE, aEFMap); @@ -118,8 +236,8 @@ Standard_Integer GEOMImpl_MirrorDriver::Execute(TFunction_Logbook& log) const const gp_Dir dir = pos.Direction(); /* Main direction of the plane (Z axis) */ gp_Ax2 aPln (loc, dir); aTrsf.SetMirror(aPln); - - } else if (aType == MIRROR_AXIS || aType == MIRROR_AXIS_COPY) { + } + else if (aType == MIRROR_AXIS || aType == MIRROR_AXIS_COPY) { Handle(GEOM_Function) anAxis = TI.GetAxis(); if (anAxis.IsNull()) return 0; TopoDS_Shape anAxisShape = anAxis->GetValue(); @@ -131,8 +249,8 @@ Standard_Integer GEOMImpl_MirrorDriver::Execute(TFunction_Logbook& log) const gp_Vec aV (aP1, aP2); gp_Ax1 anAx1 (aP1, aV); aTrsf.SetMirror(anAx1); - - } else if (aType == MIRROR_POINT || aType == MIRROR_POINT_COPY) { + } + else if (aType == MIRROR_POINT || aType == MIRROR_POINT_COPY) { Handle(GEOM_Function) aPoint = TI.GetPoint(); if (aPoint.IsNull()) return 0; TopoDS_Shape aVertexShape = aPoint->GetValue(); @@ -141,7 +259,8 @@ Standard_Integer GEOMImpl_MirrorDriver::Execute(TFunction_Logbook& log) const gp_Pnt aP = BRep_Tool::Pnt(aVertex); aTrsf.SetMirror(aP); - } else { + } + else { return 0; } @@ -198,7 +317,5 @@ const Handle(GEOMImpl_MirrorDriver) Handle(GEOMImpl_MirrorDriver)::DownCast(cons } } - return _anOtherObject ; + return _anOtherObject; } - - diff --git a/src/GEOMImpl/GEOMImpl_Types.hxx b/src/GEOMImpl/GEOMImpl_Types.hxx index b9c6f2bdf..43727effc 100755 --- a/src/GEOMImpl/GEOMImpl_Types.hxx +++ b/src/GEOMImpl/GEOMImpl_Types.hxx @@ -93,6 +93,8 @@ #define GEOM_3DSKETCHER 44 +#define GEOM_PROJECTION 45 + //GEOM_Function types #define COPY_WITH_REF 1 @@ -154,6 +156,8 @@ #define OFFSET_SHAPE 1 #define OFFSET_SHAPE_COPY 2 +#define PROJECTION_COPY 1 + #define SCALE_SHAPE 1 #define SCALE_SHAPE_COPY 2 #define SCALE_SHAPE_AXES 3 diff --git a/src/GEOM_I/GEOM_Gen_i.cc b/src/GEOM_I/GEOM_Gen_i.cc index 2c869cbff..76e0c3fe3 100644 --- a/src/GEOM_I/GEOM_Gen_i.cc +++ b/src/GEOM_I/GEOM_Gen_i.cc @@ -2308,13 +2308,13 @@ GEOM::GEOM_Object_ptr GEOM_Gen_i::AddSubShape (GEOM::GEOM_Object_ptr theMainShap if (CORBA::is_nil(theMainShape) || theIndices.length() < 1) return GEOM::GEOM_Object::_nil(); CORBA::String_var entry = theMainShape->GetEntry(); - Handle(GEOM_Object) aMainsShape = _impl->GetObject(theMainShape->GetStudyID(), entry); - if (aMainsShape.IsNull()) return GEOM::GEOM_Object::_nil(); + Handle(GEOM_Object) aMainShape = _impl->GetObject(theMainShape->GetStudyID(), entry); + if (aMainShape.IsNull()) return GEOM::GEOM_Object::_nil(); Handle(TColStd_HArray1OfInteger) anArray = new TColStd_HArray1OfInteger(1, theIndices.length()); for(Standard_Integer i = 0; iSetValue(i+1, theIndices[i]); - Handle(GEOM_Object) anObject = _impl->AddSubShape(aMainsShape, anArray, true); + Handle(GEOM_Object) anObject = _impl->AddSubShape(aMainShape, anArray, true); if(anObject.IsNull()) return GEOM::GEOM_Object::_nil(); TCollection_AsciiString anEntry; diff --git a/src/GEOM_I/GEOM_IShapesOperations_i.cc b/src/GEOM_I/GEOM_IShapesOperations_i.cc index 2b4e93e7a..71f4ebcad 100644 --- a/src/GEOM_I/GEOM_IShapesOperations_i.cc +++ b/src/GEOM_I/GEOM_IShapesOperations_i.cc @@ -91,9 +91,9 @@ GEOM::GEOM_Object_ptr GEOM_IShapesOperations_i::MakeEdge */ //============================================================================= GEOM::GEOM_Object_ptr GEOM_IShapesOperations_i::MakeEdgeOnCurveByLength - (GEOM::GEOM_Object_ptr theCurve, - CORBA::Double theLength, - GEOM::GEOM_Object_ptr theStartPoint) + (GEOM::GEOM_Object_ptr theCurve, + CORBA::Double theLength, + GEOM::GEOM_Object_ptr theStartPoint) { GEOM::GEOM_Object_var aGEOMObject; @@ -126,8 +126,8 @@ GEOM::GEOM_Object_ptr GEOM_IShapesOperations_i::MakeEdgeOnCurveByLength //============================================================================= GEOM::GEOM_Object_ptr GEOM_IShapesOperations_i::MakeEdgeWire (GEOM::GEOM_Object_ptr theWire, - const CORBA::Double theLinearTolerance, - const CORBA::Double theAngularTolerance) + const CORBA::Double theLinearTolerance, + const CORBA::Double theAngularTolerance) { GEOM::GEOM_Object_var aGEOMObject; @@ -665,6 +665,42 @@ GEOM::GEOM_Object_ptr GEOM_IShapesOperations_i::GetSubShape return GetObject(anObject); } +//============================================================================= +/*! + * MakeSubShapes + */ +//============================================================================= +GEOM::ListOfGO* GEOM_IShapesOperations_i::MakeSubShapes (GEOM::GEOM_Object_ptr theMainShape, + const GEOM::ListOfLong& theIndices) +{ + GEOM::ListOfGO_var aSeq = new GEOM::ListOfGO; + Standard_Integer i; + + //Set a not done flag + GetOperations()->SetNotDone(); + + if (theIndices.length() < 1) + return aSeq._retn(); + + Handle(GEOM_Object) aShape = GetObjectImpl(theMainShape); + if (aShape.IsNull()) return aSeq._retn(); + + Handle(TColStd_HArray1OfInteger) anArray = new TColStd_HArray1OfInteger (1, theIndices.length()); + for (i = 0; i < theIndices.length(); i++) + anArray->SetValue(i+1, theIndices[i]); + + Handle(TColStd_HSequenceOfTransient) aHSeq = GetOperations()->MakeSubShapes(aShape, anArray); + if (!GetOperations()->IsDone() || aHSeq.IsNull()) + return aSeq._retn(); + + Standard_Integer aLength = aHSeq->Length(); + aSeq->length(aLength); + for (i = 0; i < aLength; i++) + aSeq[i] = GetObject(Handle(GEOM_Object)::DownCast(aHSeq->Value(i+1))); + + return aSeq._retn(); +} + //============================================================================= /*! * GetSubShapeIndex diff --git a/src/GEOM_I/GEOM_IShapesOperations_i.hh b/src/GEOM_I/GEOM_IShapesOperations_i.hh index 3317c0417..e13676ec7 100644 --- a/src/GEOM_I/GEOM_IShapesOperations_i.hh +++ b/src/GEOM_I/GEOM_IShapesOperations_i.hh @@ -111,6 +111,9 @@ class GEOM_I_EXPORT GEOM_IShapesOperations_i : GEOM::GEOM_Object_ptr GetSubShape (GEOM::GEOM_Object_ptr theMainShape, CORBA::Long theID); + GEOM::ListOfGO* MakeSubShapes (GEOM::GEOM_Object_ptr theMainShape, + const GEOM::ListOfLong& theIndices); + CORBA::Long GetSubShapeIndex (GEOM::GEOM_Object_ptr theMainShape, GEOM::GEOM_Object_ptr theSubShape); diff --git a/src/GEOM_I/GEOM_ITransformOperations_i.cc b/src/GEOM_I/GEOM_ITransformOperations_i.cc index 568c0e010..07da1f503 100644 --- a/src/GEOM_I/GEOM_ITransformOperations_i.cc +++ b/src/GEOM_I/GEOM_ITransformOperations_i.cc @@ -636,6 +636,33 @@ GEOM::GEOM_Object_ptr GEOM_ITransformOperations_i::OffsetShapeCopy return GetObject(anObject); } +//============================================================================= +/*! + * ProjectShapeCopy + */ +//============================================================================= +GEOM::GEOM_Object_ptr GEOM_ITransformOperations_i::ProjectShapeCopy + (GEOM::GEOM_Object_ptr theSource, + GEOM::GEOM_Object_ptr theTarget) +{ + GEOM::GEOM_Object_var aGEOMObject; + + //Set a not done flag + GetOperations()->SetNotDone(); + + //Get the input objects + Handle(GEOM_Object) aSource = GetObjectImpl(theSource); + Handle(GEOM_Object) aTarget = GetObjectImpl(theTarget); + if (aSource.IsNull() || aTarget.IsNull()) return aGEOMObject._retn(); + + //Create the projection + Handle(GEOM_Object) anObject = GetOperations()->ProjectShapeCopy(aSource, aTarget); + if (!GetOperations()->IsDone() || anObject.IsNull()) + return aGEOMObject._retn(); + + return GetObject(anObject); +} + //============================================================================= /*! * ScaleShape diff --git a/src/GEOM_I/GEOM_ITransformOperations_i.hh b/src/GEOM_I/GEOM_ITransformOperations_i.hh index a26d3db54..5d937871b 100644 --- a/src/GEOM_I/GEOM_ITransformOperations_i.hh +++ b/src/GEOM_I/GEOM_ITransformOperations_i.hh @@ -121,6 +121,9 @@ class GEOM_I_EXPORT GEOM_ITransformOperations_i : GEOM::GEOM_Object_ptr OffsetShapeCopy (GEOM::GEOM_Object_ptr theObject, CORBA::Double theOffset); + GEOM::GEOM_Object_ptr ProjectShapeCopy (GEOM::GEOM_Object_ptr theSource, + GEOM::GEOM_Object_ptr theTarget); + GEOM::GEOM_Object_ptr ScaleShape (GEOM::GEOM_Object_ptr theObject, GEOM::GEOM_Object_ptr thePoint, CORBA::Double theFactor); diff --git a/src/GEOM_SWIG/geompyDC.py b/src/GEOM_SWIG/geompyDC.py index 6ad962284..ccfdb0af5 100644 --- a/src/GEOM_SWIG/geompyDC.py +++ b/src/GEOM_SWIG/geompyDC.py @@ -2319,6 +2319,18 @@ class geompyDC(GEOM._objref_GEOM_Gen): RaiseIfFailed("ExtractSubShapes", self.ShapesOp) return ListObj + ## Get a set of sub shapes defined by their unique IDs inside theMainShape + # @param theMainShape Main shape. + # @param theIndices List of unique IDs of sub shapes inside theMainShape. + # @return List of GEOM_Objects, corresponding to found sub shapes. + # + # @ref swig_all_decompose "Example" + def SubShapes(self, aShape, anIDs): + # Example: see GEOM_TestAll.py + ListObj = self.ShapesOp.MakeSubShapes(aShape, anIDs) + RaiseIfFailed("SubShapes", self.ShapesOp) + return ListObj + # end of l4_decompose ## @} @@ -3005,6 +3017,18 @@ class geompyDC(GEOM._objref_GEOM_Gen): anObj.SetParameters(Parameters) return anObj + ## Create new object as projection of the given one on a 2D surface. + # @param theSource The source object for the projection. It can be a point, edge or wire. + # @param theTarget The target object. It can be planar or cylindrical face. + # @return New GEOM_Object, containing the projection. + # + # @ref tui_projection "Example" + def MakeProjection(self, theSource, theTarget): + # Example: see GEOM_TestAll.py + anObj = self.TrsfOp.ProjectShapeCopy(theSource, theTarget) + RaiseIfFailed("ProjectShapeCopy", self.TrsfOp) + return anObj + # ----------------------------------------------------------------------------- # Patterns # ----------------------------------------------------------------------------- diff --git a/src/TransformationGUI/Makefile.am b/src/TransformationGUI/Makefile.am index 1038e4955..a270ee2a7 100644 --- a/src/TransformationGUI/Makefile.am +++ b/src/TransformationGUI/Makefile.am @@ -15,13 +15,11 @@ # 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 TRANSFORMATIONGUI : # File : Makefile.am # Author : Alexander BORODIN, Open CASCADE S.A.S. (alexander.borodin@opencascade.com) # Package : TransformationGUI -# + include $(top_srcdir)/adm_local/unix/make_common_starter.am # header files @@ -34,6 +32,7 @@ salomeinclude_HEADERS = \ TransformationGUI_MirrorDlg.h \ TransformationGUI_ScaleDlg.h \ TransformationGUI_OffsetDlg.h \ + TransformationGUI_ProjectionDlg.h \ TransformationGUI_PositionDlg.h # Libraries targets @@ -48,6 +47,7 @@ dist_libTransformationGUI_la_SOURCES = \ TransformationGUI_MirrorDlg.h \ TransformationGUI_ScaleDlg.h \ TransformationGUI_OffsetDlg.h \ + TransformationGUI_ProjectionDlg.h \ TransformationGUI_PositionDlg.h \ \ TransformationGUI.cxx \ @@ -58,6 +58,7 @@ dist_libTransformationGUI_la_SOURCES = \ TransformationGUI_MirrorDlg.cxx \ TransformationGUI_ScaleDlg.cxx \ TransformationGUI_OffsetDlg.cxx \ + TransformationGUI_ProjectionDlg.cxx \ TransformationGUI_PositionDlg.cxx MOC_FILES = \ @@ -68,6 +69,7 @@ MOC_FILES = \ TransformationGUI_MirrorDlg_moc.cxx \ TransformationGUI_ScaleDlg_moc.cxx \ TransformationGUI_OffsetDlg_moc.cxx \ + TransformationGUI_ProjectionDlg_moc.cxx \ TransformationGUI_PositionDlg_moc.cxx nodist_libTransformationGUI_la_SOURCES = \ @@ -99,4 +101,3 @@ libTransformationGUI_la_LDFLAGS = \ ../GEOMFiltersSelection/libGEOMFiltersSelection.la \ ../GEOMBase/libGEOMBase.la \ $(CAS_LDPATH) -lTKShHealing - diff --git a/src/TransformationGUI/TransformationGUI.cxx b/src/TransformationGUI/TransformationGUI.cxx index 70313374b..bf709209f 100644 --- a/src/TransformationGUI/TransformationGUI.cxx +++ b/src/TransformationGUI/TransformationGUI.cxx @@ -18,12 +18,11 @@ // 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.cxx // Author : Damien COQUERET, Open CASCADE S.A.S. -// + #include "TransformationGUI.h" #include @@ -46,6 +45,7 @@ #include "TransformationGUI_MirrorDlg.h" // Method MIRROR #include "TransformationGUI_ScaleDlg.h" // Method SCALE #include "TransformationGUI_OffsetDlg.h" // Method OFFSET +#include "TransformationGUI_ProjectionDlg.h" // Method PROJECTION #include "TransformationGUI_PositionDlg.h" // Method POSITION //======================================================================= @@ -97,6 +97,9 @@ bool TransformationGUI::OnGUIEvent( int theCommandID, SUIT_Desktop* parent ) case GEOMOp::OpOffset: // OFFSET aDlg = new TransformationGUI_OffsetDlg( getGeometryGUI(), parent ); break; + case GEOMOp::OpProjection: // PROJECTION + aDlg = new TransformationGUI_ProjectionDlg( getGeometryGUI(), parent ); + break; case GEOMOp::OpMultiTranslate: // MULTI TRANSLATION aDlg = new TransformationGUI_MultiTranslationDlg( getGeometryGUI(), parent ); break; diff --git a/src/TransformationGUI/TransformationGUI_ProjectionDlg.cxx b/src/TransformationGUI/TransformationGUI_ProjectionDlg.cxx new file mode 100644 index 000000000..6a1e39f98 --- /dev/null +++ b/src/TransformationGUI/TransformationGUI_ProjectionDlg.cxx @@ -0,0 +1,277 @@ +// Copyright (C) 2007-2010 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. +// +// 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 + +// File : TransformationGUI_ProjectionDlg.cxx +// Author : Lucien PIGNOLONI, Open CASCADE S.A.S. + +#include "TransformationGUI.h" +#include "TransformationGUI_ProjectionDlg.h" + +#include +#include +#include + +#include +#include +#include +#include + +//================================================================================= +// class : TransformationGUI_ProjectionDlg() +// purpose : Constructs a TransformationGUI_ProjectionDlg 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_ProjectionDlg::TransformationGUI_ProjectionDlg (GeometryGUI* theGeometryGUI, + QWidget* parent, bool modal, Qt::WindowFlags fl) + : GEOMBase_Skeleton(theGeometryGUI, parent, modal, fl) +{ + QPixmap image0 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_PROJECTION"))); + QPixmap image1 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_SELECT"))); + + setWindowTitle(tr("GEOM_PROJECTION_TITLE")); + + mainFrame()->GroupConstructors->setTitle(tr("GEOM_PROJECTION")); + mainFrame()->RadioButton1->setIcon(image0); + mainFrame()->RadioButton2->setAttribute(Qt::WA_DeleteOnClose); + mainFrame()->RadioButton2->close(); + mainFrame()->RadioButton3->setAttribute(Qt::WA_DeleteOnClose); + mainFrame()->RadioButton3->close(); + + myGroup = new DlgRef_2Sel (centralWidget()); + + myGroup->GroupBox1->setTitle(tr("GEOM_ARGUMENTS")); + myGroup->TextLabel1->setText(tr("GEOM_SOURCE_OBJECT")); + myGroup->TextLabel2->setText(tr("GEOM_TARGET_OBJECT")); + myGroup->PushButton1->setIcon(image1); + myGroup->PushButton2->setIcon(image1); + myGroup->LineEdit1->setReadOnly(true); + myGroup->LineEdit2->setReadOnly(true); + + QVBoxLayout* layout = new QVBoxLayout(centralWidget()); + layout->setMargin(0); layout->setSpacing(6); + layout->addWidget(myGroup); + + setHelpFileName("projection_operation_page.html"); + + // Initialisation + Init(); +} + +//================================================================================= +// function : ~TransformationGUI_ProjectionDlg() +// purpose : Destroys the object and frees any allocated resources +//================================================================================= +TransformationGUI_ProjectionDlg::~TransformationGUI_ProjectionDlg() +{ +} + +//================================================================================= +// function : Init() +// purpose : +//================================================================================= +void TransformationGUI_ProjectionDlg::Init() +{ + mainFrame()->GroupBoxPublish->show(); + + // init variables + myEditCurrentArgument = myGroup->LineEdit1; + + myGroup->LineEdit1->setText(""); + myGroup->LineEdit2->setText(""); + myObject1.nullify(); + myObject2.nullify(); + + showOnlyPreviewControl(); + + // signals and slots connections + connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk())); + connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply())); + + connect(myGroup->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument())); + connect(myGroup->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument())); + + connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), + SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())); + + initName(mainFrame()->GroupConstructors->title()); + + setTabOrder(mainFrame()->GroupConstructors, mainFrame()->GroupBoxName); + setTabOrder(mainFrame()->GroupBoxName, mainFrame()->GroupMedium); + setTabOrder(mainFrame()->GroupMedium, mainFrame()->GroupButtons); + + mainFrame()->RadioButton1->setFocus(); + + globalSelection(GEOM_ALLSHAPES); + + myGroup->PushButton1->click(); + SelectionIntoArgument(); + resize(100,100); +} + +//================================================================================= +// function : ClickOnOk() +// purpose : +//================================================================================= +void TransformationGUI_ProjectionDlg::ClickOnOk() +{ + setIsApplyAndClose(true); + if (ClickOnApply()) + ClickOnCancel(); +} + +//================================================================================= +// function : ClickOnApply() +// purpose : +//================================================================================= +bool TransformationGUI_ProjectionDlg::ClickOnApply() +{ + if (!onAccept()) + return false; + + initName(); + // activate selection and connect selection manager + myGroup->PushButton1->click(); + return true; +} + +//================================================================================= +// function : SelectionIntoArgument() +// purpose : Called when selection is changed or on dialog initialization or activation +//================================================================================= +void TransformationGUI_ProjectionDlg::SelectionIntoArgument() +{ + myEditCurrentArgument->setText(""); + + GEOM::GeomObjPtr aSelectedObject = getSelected(TopAbs_SHAPE); + TopoDS_Shape aShape; + if (aSelectedObject && GEOMBase::GetShape(aSelectedObject.get(), aShape) && !aShape.IsNull()) { + QString aName = GEOMBase::GetName(aSelectedObject.get()); + myEditCurrentArgument->setText(aName); + + // clear selection + disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0); + myGeomGUI->getApp()->selectionMgr()->clearSelected(); + connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()), + this, SLOT(SelectionIntoArgument())); + + if (myEditCurrentArgument == myGroup->LineEdit1) { + myObject1 = aSelectedObject; + if (!myObject2) + myGroup->PushButton2->click(); + } + else if (myEditCurrentArgument == myGroup->LineEdit2) { + myObject2 = aSelectedObject; + if (!myObject1) + myGroup->PushButton1->click(); + } + } + else { + if (myEditCurrentArgument == myGroup->LineEdit1) myObject1.nullify(); + else if (myEditCurrentArgument == myGroup->LineEdit2) myObject2.nullify(); + } +} + +//================================================================================= +// function : SetEditCurrentArgument() +// purpose : +//================================================================================= +void TransformationGUI_ProjectionDlg::SetEditCurrentArgument() +{ + QPushButton* send = (QPushButton*)sender(); + + if (send == myGroup->PushButton1) { + myEditCurrentArgument = myGroup->LineEdit1; + + myGroup->PushButton2->setDown(false); + myGroup->LineEdit2->setEnabled(false); + } + else if (send == myGroup->PushButton2) { + myEditCurrentArgument = myGroup->LineEdit2; + + myGroup->PushButton1->setDown(false); + myGroup->LineEdit1->setEnabled(false); + } + + // enable line edit + myEditCurrentArgument->setEnabled(true); + myEditCurrentArgument->setFocus(); + // after setFocus(), because it will be setDown(false) when loses focus + send->setDown(true); +} + +//================================================================================= +// function : ActivateThisDialog() +// purpose : +//================================================================================= +void TransformationGUI_ProjectionDlg::ActivateThisDialog() +{ + GEOMBase_Skeleton::ActivateThisDialog(); + + connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()), + this, SLOT(SelectionIntoArgument())); + processPreview(); +} + +//================================================================================= +// function : enterEvent() +// purpose : when mouse enter onto the QWidget +//================================================================================= +void TransformationGUI_ProjectionDlg::enterEvent (QEvent*) +{ + if (!mainFrame()->GroupConstructors->isEnabled()) + ActivateThisDialog(); +} + +//================================================================================= +// function : createOperation +// purpose : +//================================================================================= +GEOM::GEOM_IOperations_ptr TransformationGUI_ProjectionDlg::createOperation() +{ + return getGeomEngine()->GetITransformOperations(getStudyId()); +} + +//================================================================================= +// function : isValid +// purpose : +//================================================================================= +bool TransformationGUI_ProjectionDlg::isValid (QString&) +{ + return myObject1 && myObject2; +} + +//================================================================================= +// function : execute +// purpose : +//================================================================================= +bool TransformationGUI_ProjectionDlg::execute (ObjectList& objects) +{ + GEOM::GEOM_Object_var anObj; + + GEOM::GEOM_ITransformOperations_var anOper = GEOM::GEOM_ITransformOperations::_narrow(getOperation()); + anObj = anOper->ProjectShapeCopy(myObject1.get(), myObject2.get()); + if (!anObj->_is_nil()) + objects.push_back(anObj._retn()); + + return true; +} diff --git a/src/TransformationGUI/TransformationGUI_ProjectionDlg.h b/src/TransformationGUI/TransformationGUI_ProjectionDlg.h new file mode 100644 index 000000000..e7c34a878 --- /dev/null +++ b/src/TransformationGUI/TransformationGUI_ProjectionDlg.h @@ -0,0 +1,70 @@ +// Copyright (C) 2007-2010 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. +// +// 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 + +// File : TransformationGUI_ProjectionDlg.h +// Author : Lucien PIGNOLONI, Open CASCADE S.A.S. + +#ifndef TRANSFORMATIONGUI_PROJECTIONDLG_H +#define TRANSFORMATIONGUI_PROJECTIONDLG_H + +#include "GEOMBase_Skeleton.h" +#include "GEOM_GenericObjPtr.h" + +class DlgRef_2Sel; + +//================================================================================= +// class : TransformationGUI_ProjectionDlg +// purpose : +//================================================================================= +class TransformationGUI_ProjectionDlg : public GEOMBase_Skeleton +{ + Q_OBJECT + +public: + TransformationGUI_ProjectionDlg (GeometryGUI*, QWidget* = 0, + bool = false, Qt::WindowFlags = 0 ); + ~TransformationGUI_ProjectionDlg(); + +protected: + // redefined from GEOMBase_Helper + virtual GEOM::GEOM_IOperations_ptr createOperation(); + virtual bool isValid (QString&); + virtual bool execute (ObjectList&); + +private: + void Init(); + void enterEvent (QEvent*); + +private: + GEOM::GeomObjPtr myObject1; + GEOM::GeomObjPtr myObject2; + + DlgRef_2Sel* myGroup; + +private slots: + void ClickOnOk(); + bool ClickOnApply(); + void SetEditCurrentArgument(); + void SelectionIntoArgument(); + void ActivateThisDialog(); +}; + +#endif // TRANSFORMATIONGUI_PROJECTIONDLG_H -- 2.39.2