From dfa458fe08e72a485d4e632f0ffa52e24274e9c5 Mon Sep 17 00:00:00 2001 From: dcq Date: Fri, 27 Feb 2004 13:02:11 +0000 Subject: [PATCH] DCQ : Add Position Functions. --- Makefile.in | 4 + idl/GEOM_Gen.idl | 5 + resources/GEOM_en.xml | 20 +- resources/position.png | Bin 0 -> 311 bytes resources/positionface.png | Bin 0 -> 306 bytes resources/positionpoint.png | Bin 0 -> 310 bytes resources/positionvect.png | Bin 0 -> 310 bytes src/GEOM/GEOM_Gen_i.cc | 117 +++++ src/GEOM/GEOM_Gen_i.hh | 15 +- src/GEOMContext/GEOM_icons.po | 13 + src/GEOMContext/GEOM_msg_en.po | 15 + src/GEOMGUI/GeometryGUI.cxx | 9 +- src/TransformationGUI/Makefile.in | 4 +- src/TransformationGUI/TransformationGUI.cxx | 72 ++- src/TransformationGUI/TransformationGUI.h | 4 + .../TransformationGUI_PositionDlg.cxx | 410 ++++++++++++++++++ .../TransformationGUI_PositionDlg.h | 91 ++++ 17 files changed, 753 insertions(+), 26 deletions(-) create mode 100644 resources/position.png create mode 100644 resources/positionface.png create mode 100644 resources/positionpoint.png create mode 100644 resources/positionvect.png create mode 100644 src/TransformationGUI/TransformationGUI_PositionDlg.cxx create mode 100644 src/TransformationGUI/TransformationGUI_PositionDlg.h diff --git a/Makefile.in b/Makefile.in index 65bc47c44..734adeef8 100644 --- a/Makefile.in +++ b/Makefile.in @@ -91,6 +91,10 @@ planepointvector.png \ planeworkingface.png \ point2.png \ pointonedge.png \ +position.png \ +positionface.png \ +positionpoint.png \ +positionvect.png \ prism.png \ revol.png \ rotate.png \ diff --git a/idl/GEOM_Gen.idl b/idl/GEOM_Gen.idl index 706e68391..54fab87b0 100644 --- a/idl/GEOM_Gen.idl +++ b/idl/GEOM_Gen.idl @@ -120,6 +120,11 @@ module GEOM GEOM_Shape MakeRotation(in GEOM_Shape shape, in AxisStruct axis, in double angle) raises (SALOME::SALOME_Exception) ; + GEOM_Shape MakePosition(in GEOM_Shape shape1, + in GEOM_Shape shape2, + in GEOM_Shape::ListOfSubShapeID ListOfID1, + in GEOM_Shape::ListOfSubShapeID ListOfID2, + in short typeofshape) raises (SALOME::SALOME_Exception) ; GEOM_Shape MakeScaleTransform(in GEOM_Shape shape, in PointStruct theCenterofScale, in double factor) raises (SALOME::SALOME_Exception) ; diff --git a/resources/GEOM_en.xml b/resources/GEOM_en.xml index 4a0727573..11142cd08 100644 --- a/resources/GEOM_en.xml +++ b/resources/GEOM_en.xml @@ -112,11 +112,12 @@ - - + + + - - + + @@ -139,7 +140,7 @@ - + @@ -252,11 +253,12 @@ - - + + + - - + + diff --git a/resources/position.png b/resources/position.png new file mode 100644 index 0000000000000000000000000000000000000000..7048b5e6673da9235ed1fc684bf04bd865f16a3e GIT binary patch literal 311 zcmeAS@N?(olHy`uVBq!ia0vp^A|TAc1|)ksWqE-VXMsm#F#`kNVGw3Kp1&dmDEQLT z#WAE}&e|!yTrCDXZpGgY3VVEHaEjr$EAq(ch3TGi=G}&iO#e!zi^+FvU4K$}8iz~$ z*}txbx1}iv?h0?uyK&~lbRm{a9FL^lf8fr!vB@D;UFpM#51ZR{CNYLZwa9H_j(vYX z+1ZJ)A|yFv22*$3db^ag_`S7kebfVkn$c<6P9!w%a`LJsV{Q+c*g zVUp{Cc@L}DukV&g`Vht3oG>qK!}Gt*ceAyWn2(t{HT_{L5scWYHbYvb!iI5vOtPfT z-`i_-mxi0FN5nkl-SA;mn$5w2%MmX_eG4zvFpF=t)FDRCt`NltBu^AP`08>?J1%k^=~nMZk?PE&^U7*ZEzv2BV|3 zO&1?RjL(_JL?RIVHT8>uZNoq!OpgiEa;QmPiWf)_#68yV3v4->z_d<8V9Riug9K>+ z2inZRW;S5U5Z?iw)hHE~z^>O{fIY9bfST7^Eo)wNV3Bj2(z9}i4jdSnR@F7IGtekn z90In2EaN~Bi5IYCnAyP0=CT2q!Du7uKS9t{@v_yJgWRkLO=bQ`O^swpnoC)#u)l-QkBL;wH)07*qo IM6N<$g1{quZ~y=R literal 0 HcmV?d00001 diff --git a/resources/positionvect.png b/resources/positionvect.png new file mode 100644 index 0000000000000000000000000000000000000000..9994dd2e394d16ea965cabbdbb4c29841b63628c GIT binary patch literal 310 zcmeAS@N?(olHy`uVBq!ia0vp^A|TAc1|)ksWqE-VXMsm#F#`kNVGw3Kp1&dmDEPwD z#WAE}&e|!STrCCyuCL!r688AO&{(9HBCH|qwC-VPo&GJ4GbvlDKblL<3+*>@QTUbp zskJZru7lDFM@Qdk!-q>O8rLxG|0z?~=vyr+@vW01N1|-wgix&mv&97M${4<`IM}AR zj?redX2=Yt*>U$7qT}kBrtR66xAWOn9-k%yzh%4;;xhEM__Eo4oRR(xmop%nVINRjS#2^MHP4@O1TaS?83{ F1OV}ZdC33( literal 0 HcmV?d00001 diff --git a/src/GEOM/GEOM_Gen_i.cc b/src/GEOM/GEOM_Gen_i.cc index 081520760..a29a34d95 100644 --- a/src/GEOM/GEOM_Gen_i.cc +++ b/src/GEOM/GEOM_Gen_i.cc @@ -46,6 +46,7 @@ using namespace std; #include #include #include +#include #include #include #include @@ -64,6 +65,7 @@ using namespace std; #include #endif #include +#include #include #include #include @@ -4420,6 +4422,121 @@ GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakeRotation( GEOM::GEOM_Shape_ptr myShape, } +//================================================================================= +// function : MakePosition() +// purpose : +//================================================================================= +GEOM::GEOM_Shape_ptr GEOM_Gen_i::MakePosition(GEOM::GEOM_Shape_ptr shape1, + GEOM::GEOM_Shape_ptr shape2, + const GEOM::GEOM_Shape::ListOfSubShapeID& ListOfID1, + const GEOM::GEOM_Shape::ListOfSubShapeID& ListOfID2, + const CORBA::Short typeofshape) + throw (SALOME::SALOME_Exception) +{ + GEOM::GEOM_Shape_var result; + TopoDS_Shape tds; + TopoDS_Shape aShape1 = GetTopoShape(shape1); + TopoDS_Shape aShape2 = GetTopoShape(shape2); + if(aShape1.IsNull() || aShape2.IsNull()) { + THROW_SALOME_CORBA_EXCEPTION("MakePosition aborted : null shape during operation", SALOME::BAD_PARAM); + } + + try { + gp_Trsf theTransformation; + TopoDS_Shape S1, S2; + + GetShapeFromIndex(aShape1, (TopAbs_ShapeEnum)typeofshape, ListOfID1[0], S1); + GetShapeFromIndex(aShape2, (TopAbs_ShapeEnum)typeofshape, ListOfID2[0], S2); + + if(S1.ShapeType() == TopAbs_VERTEX && S2.ShapeType() == TopAbs_VERTEX) { + gp_Pnt Pt1 = BRep_Tool::Pnt(TopoDS::Vertex(S1)); + gp_Pnt Pt2 = BRep_Tool::Pnt(TopoDS::Vertex(S2)); + + gp_Vec theVector(Pt1, Pt2); + theTransformation.SetTranslation(theVector); + } + else if(S1.ShapeType() == TopAbs_EDGE && S2.ShapeType() == TopAbs_EDGE) { + Standard_Real f, l; + gp_Pnt Pt1, Pt2; + gp_Vec V1, V2; + + Handle(Geom_Curve) C = BRep_Tool::Curve(TopoDS::Edge(S1), f, l); + C->D1(f, Pt1, V1); + C = BRep_Tool::Curve(TopoDS::Edge(S2), f, l); + C->D1(f, Pt2, V2); + + gp_Vec theVector(Pt1, Pt2); + theTransformation.SetTranslation(theVector); + + if(!V1.IsParallel(V2, Precision::Angular())) { + gp_Vec VN = V1.Crossed(V2); + double Angle = V1.Angle(V2); + + gp_Dir D(VN.X(), VN.Y(), VN.Z()); + gp_Ax1 AX(Pt1, D); + + gp_Trsf TheRot; + TheRot.SetRotation(AX, Angle); + theTransformation = theTransformation * TheRot; + } + } + else if(S1.ShapeType() == TopAbs_FACE && S2.ShapeType() == TopAbs_FACE) { + TopoDS_Edge E1, E2; + Standard_Real f, l; + gp_Pnt P1, P2; + gp_Vec D1, D2, N1, N2, V1, V2; + + TopExp_Explorer Exp1(S1, TopAbs_EDGE); + TopExp_Explorer Exp2(S2, TopAbs_EDGE); + + for(; Exp1.More(); Exp1.Next()) { + E1 = TopoDS::Edge(Exp1.Current()); + if(!BRep_Tool::Degenerated(E1)) + break; + } + for(; Exp2.More(); Exp2.Next()) { + E2 = TopoDS::Edge(Exp2.Current()); + if(!BRep_Tool::Degenerated(E2)) + break; + } + + Handle(Geom_Curve) C = BRep_Tool::Curve(E1, f, l); + C->D1(f, P1, D1); + Handle(Geom2d_Curve) C2 = BRep_Tool::CurveOnSurface(E1, TopoDS::Face(S1), f, l); + gp_Pnt2d P2d = C2->Value(f); + Handle(Geom_Surface) S = BRep_Tool::Surface(TopoDS::Face(S1)); + S->D1(P2d.X(), P2d.Y(), P1, V1, V2); + N1 = V1^V2; + + C = BRep_Tool::Curve(E2, f, l); + C->D1(f, P2, D2); + C2 = BRep_Tool::CurveOnSurface(E2, TopoDS::Face(S2), f, l); + P2d = C2->Value(f); + S = BRep_Tool::Surface(TopoDS::Face(S2)); + S->D1(P2d.X(), P2d.Y(), P2, V1, V2); + N2 = V1^V2; + + gp_Ax3 Ax1(P1, N1, D1); + gp_Ax3 Ax2(P2, N2, D2); + + theTransformation.SetDisplacement(Ax1, Ax2); + } + + BRepBuilderAPI_Transform myBRepTransformation(aShape1, theTransformation, Standard_False); + tds = myBRepTransformation.Shape(); + } + catch(Standard_Failure) { + THROW_SALOME_CORBA_EXCEPTION("Exception catched in GEOM_Gen_i::MakePosition", SALOME::BAD_PARAM); + } + + if(!tds.IsNull()) { + result = CreateObject(tds); + InsertInLabelOneArgument(aShape1, shape1, tds, result, myCurrentOCAFDoc); + } + return result; +} + + //================================================================================= // function : MakeScaleTransform() // purpose : Make a shape multipling another by a scale factor diff --git a/src/GEOM/GEOM_Gen_i.hh b/src/GEOM/GEOM_Gen_i.hh index 9003d058d..f97fa004c 100644 --- a/src/GEOM/GEOM_Gen_i.hh +++ b/src/GEOM/GEOM_Gen_i.hh @@ -401,21 +401,28 @@ class GEOM_Gen_i: public POA_GEOM::GEOM_Gen, //---------------------------------------------------------------------// // Transformations Operations // //---------------------------------------------------------------------// - // Copy - GEOM::GEOM_Shape_ptr MakeCopy( GEOM::GEOM_Shape_ptr shape) + // Copy + GEOM::GEOM_Shape_ptr MakeCopy(GEOM::GEOM_Shape_ptr shape) throw (SALOME::SALOME_Exception) ; // Translation - GEOM::GEOM_Shape_ptr MakeTranslation( GEOM::GEOM_Shape_ptr shape, + GEOM::GEOM_Shape_ptr MakeTranslation(GEOM::GEOM_Shape_ptr shape, CORBA::Double x, CORBA::Double y, CORBA::Double z) throw (SALOME::SALOME_Exception) ; // Rotation - GEOM::GEOM_Shape_ptr MakeRotation( GEOM::GEOM_Shape_ptr shape, + GEOM::GEOM_Shape_ptr MakeRotation(GEOM::GEOM_Shape_ptr shape, const GEOM::AxisStruct& axis, CORBA::Double angle) throw (SALOME::SALOME_Exception) ; + // Position + GEOM::GEOM_Shape_ptr MakePosition(GEOM::GEOM_Shape_ptr shape1, + GEOM::GEOM_Shape_ptr shape2, + const GEOM::GEOM_Shape::ListOfSubShapeID& ListOfID1, + const GEOM::GEOM_Shape::ListOfSubShapeID& ListOfID2, + const CORBA::Short typeofshape) + throw (SALOME::SALOME_Exception) ; // Create a shape using a scale factor GEOM::GEOM_Shape_ptr MakeScaleTransform(GEOM::GEOM_Shape_ptr shape, const GEOM::PointStruct& theCenterOfScale, diff --git a/src/GEOMContext/GEOM_icons.po b/src/GEOMContext/GEOM_icons.po index bea2c564c..8a4f80f42 100644 --- a/src/GEOMContext/GEOM_icons.po +++ b/src/GEOMContext/GEOM_icons.po @@ -382,5 +382,18 @@ msgstr "bezier.png" msgid "ICON_DLG_INTERPOL" msgstr "interpol.png" +#PositionDlg +msgid "ICON_DLG_POSITION" +msgstr "position.png" +#PositionDlg +msgid "ICON_DLG_POS_POINT" +msgstr "positionpoint.png" +#PositionDlg +msgid "ICON_DLG_POS_VECT" +msgstr "positionvect.png" + +#PositionDlg +msgid "ICON_DLG_POS_FACE" +msgstr "positionface.png" diff --git a/src/GEOMContext/GEOM_msg_en.po b/src/GEOMContext/GEOM_msg_en.po index 895143100..035c8e8bd 100644 --- a/src/GEOMContext/GEOM_msg_en.po +++ b/src/GEOMContext/GEOM_msg_en.po @@ -1371,3 +1371,18 @@ msgstr "Nb. Sequences" msgid "GEOM_IS_IN_LOOP" msgstr "In Loop" + +msgid "GEOM_POSITION" +msgstr "Position" + +msgid "GEOM_POSITION_TITLE" +msgstr "Position Of An Object" + +msgid "GEOM_POS_VERTEX" +msgstr "Position by Points" + +msgid "GEOM_POS_EDGE" +msgstr "Position by Edges" + +msgid "GEOM_POS_FACE" +msgstr "Position by Faces" diff --git a/src/GEOMGUI/GeometryGUI.cxx b/src/GEOMGUI/GeometryGUI.cxx index d0521d3cb..f0b0b1f9e 100644 --- a/src/GEOMGUI/GeometryGUI.cxx +++ b/src/GEOMGUI/GeometryGUI.cxx @@ -222,10 +222,11 @@ bool GeometryGUI::OnGUIEvent(int theCommandID, QAD_Desktop* parent) } else if(theCommandID == 5021 || // MENU TRANSFORMATION - TRANSLATION theCommandID == 5022 || // MENU TRANSFORMATION - ROTATION - theCommandID == 5023 || // MENU TRANSFORMATION - MIRROR - theCommandID == 5024 || // MENU TRANSFORMATION - SCALE - theCommandID == 5025 || // MENU TRANSFORMATION - MULTI-TRANSLATION - theCommandID == 5026) { // MENU TRANSFORMATION - MULTI-ROTATION + theCommandID == 5023 || // MENU TRANSFORMATION - POSITION + theCommandID == 5024 || // MENU TRANSFORMATION - MIRROR + theCommandID == 5025 || // MENU TRANSFORMATION - SCALE + theCommandID == 5026 || // MENU TRANSFORMATION - MULTI-TRANSLATION + theCommandID == 5027) { // MENU TRANSFORMATION - MULTI-ROTATION if(!GeomGUI->LoadLibrary("libTransformationGUI.so")) return false; } diff --git a/src/TransformationGUI/Makefile.in b/src/TransformationGUI/Makefile.in index d19e3d26c..0c3495e54 100644 --- a/src/TransformationGUI/Makefile.in +++ b/src/TransformationGUI/Makefile.in @@ -45,6 +45,7 @@ LIB_SRC = TransformationGUI.cxx \ TransformationGUI_MultiRotationDlg.cxx \ TransformationGUI_TranslationDlg.cxx \ TransformationGUI_RotationDlg.cxx \ + TransformationGUI_PositionDlg.cxx \ TransformationGUI_MirrorDlg.cxx \ TransformationGUI_ScaleDlg.cxx @@ -54,6 +55,7 @@ LIB_MOC = \ TransformationGUI_MultiRotationDlg.h \ TransformationGUI_TranslationDlg.h \ TransformationGUI_RotationDlg.h \ + TransformationGUI_PositionDlg.h \ TransformationGUI_MirrorDlg.h \ TransformationGUI_ScaleDlg.h @@ -66,6 +68,6 @@ LIB_SERVER_IDL = CPPFLAGS += $(QT_INCLUDES) $(VTK_INCLUDES) $(OCC_INCLUDES) $(PYTHON_INCLUDES) -I${KERNEL_ROOT_DIR}/include/salome CXXFLAGS += -I${KERNEL_ROOT_DIR}/include/salome -LDFLAGS += -lGEOMFiltersSelection -lGEOMBase +LDFLAGS += -lGEOMFiltersSelection -lDisplayGUI @CONCLUDE@ diff --git a/src/TransformationGUI/TransformationGUI.cxx b/src/TransformationGUI/TransformationGUI.cxx index 54ea7d019..ca544e7c9 100644 --- a/src/TransformationGUI/TransformationGUI.cxx +++ b/src/TransformationGUI/TransformationGUI.cxx @@ -29,12 +29,16 @@ using namespace std; #include "TransformationGUI.h" +#include "BRepAdaptor_Curve.hxx" +#include "QAD_RightFrame.h" +#include "OCCViewer_Viewer3d.h" #include "SALOMEGUI_QtCatchCorbaException.hxx" #include "TransformationGUI_MultiTranslationDlg.h" // Method MULTI TRANSLATION #include "TransformationGUI_MultiRotationDlg.h" // Method MULTI ROTATION #include "TransformationGUI_TranslationDlg.h" // Method TRANSLATION #include "TransformationGUI_RotationDlg.h" // Method ROTATION +#include "TransformationGUI_PositionDlg.h" // Method POSITION #include "TransformationGUI_MirrorDlg.h" // Method MIRROR #include "TransformationGUI_ScaleDlg.h" // Method SCALE @@ -73,31 +77,41 @@ bool TransformationGUI::OnGUIEvent(int theCommandID, QAD_Desktop* parent) switch (theCommandID) { case 5021: // TRANSLATION - { + { TransformationGUI_TranslationDlg *aDlg = new TransformationGUI_TranslationDlg(parent, "", myTransformationGUI, Sel); break; } case 5022: // ROTATION - { + { TransformationGUI_RotationDlg *aDlg = new TransformationGUI_RotationDlg(parent, "", myTransformationGUI, Sel); break; } - case 5023: // MIRROR - { + case 5023: // POSITION + { + Handle(AIS_InteractiveContext) ic; + if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_OCC) { + OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer(); + ic = v3d->getAISContext(); + } + TransformationGUI_PositionDlg *aDlg = new TransformationGUI_PositionDlg(parent, "", myTransformationGUI, Sel, ic); + break; + } + case 5024: // MIRROR + { TransformationGUI_MirrorDlg *aDlg = new TransformationGUI_MirrorDlg(parent, "", myTransformationGUI, Sel); break; } - case 5024: // SCALE + case 5025: // SCALE { TransformationGUI_ScaleDlg *aDlg = new TransformationGUI_ScaleDlg(parent, "", myTransformationGUI, Sel ); break; } - case 5025: // MULTI TRANSLATION + case 5026: // MULTI TRANSLATION { TransformationGUI_MultiTranslationDlg *aDlg = new TransformationGUI_MultiTranslationDlg(parent, "", myTransformationGUI, Sel); break; } - case 5026: // MULTI ROTATION + case 5027: // MULTI ROTATION { TransformationGUI_MultiRotationDlg *aDlg = new TransformationGUI_MultiRotationDlg(parent, "", myTransformationGUI, Sel); break; @@ -148,7 +162,7 @@ void TransformationGUI::MakeRotationAndDisplay(GEOM::GEOM_Shape_ptr Shape, const GEOM::GEOM_Shape_var result = myGeom->MakeRotation(Shape, axis, angle); if(result->_is_nil()) { QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_ABORT")); - return ; + return; } result->NameType(Shape->NameType()); if(myGeomBase->Display(result)) @@ -161,6 +175,48 @@ void TransformationGUI::MakeRotationAndDisplay(GEOM::GEOM_Shape_ptr Shape, const } +//======================================================================================= +// function : MakePositionAndDisplay() +// purpose : +//======================================================================================= +void TransformationGUI::MakePositionAndDisplay(GEOM::GEOM_Shape_ptr ShapePtr1, + GEOM::GEOM_Shape_ptr ShapePtr2, + const TopoDS_Shape& Shape1, + const TopoDS_Shape& Shape2, + const TopoDS_Shape& SubShape1, + const TopoDS_Shape& SubShape2) +{ + try { + GEOM::GEOM_Shape_var result; + + if(SubShape1.ShapeType() == SubShape2.ShapeType()) { + GEOM::GEOM_Shape::ListOfSubShapeID_var ListOfID1 = new GEOM::GEOM_Shape::ListOfSubShapeID; + GEOM::GEOM_Shape::ListOfSubShapeID_var ListOfID2 = new GEOM::GEOM_Shape::ListOfSubShapeID; + + ListOfID1->length(1); + ListOfID2->length(1); + + ListOfID1[0] = myGeomBase->GetIndex(SubShape1, Shape1, SubShape1.ShapeType()); + ListOfID2[0] = myGeomBase->GetIndex(SubShape2, Shape2, SubShape2.ShapeType()); + + result = myGeom->MakePosition(ShapePtr1, ShapePtr2, ListOfID1, ListOfID2, SubShape1.ShapeType()); + } + + if(result->_is_nil()) { + QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_ABORT")); + return; + } + result->NameType(ShapePtr1->NameType()); + if(myGeomBase->Display(result)) + QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_DONE")); + } + catch(const SALOME::SALOME_Exception& S_ex) { + QtCatchCorbaException(S_ex); + } + return; +} + + //===================================================================================== // function : MakeMirrorAndDisplay() // purpose : diff --git a/src/TransformationGUI/TransformationGUI.h b/src/TransformationGUI/TransformationGUI.h index f8451c60e..73995005b 100644 --- a/src/TransformationGUI/TransformationGUI.h +++ b/src/TransformationGUI/TransformationGUI.h @@ -49,6 +49,10 @@ public : void MakeTranslationAndDisplay(GEOM::GEOM_Shape_ptr Shape, const gp_Vec V); void MakeRotationAndDisplay(GEOM::GEOM_Shape_ptr Shape, const gp_Pnt loc, const gp_Dir dir, const Standard_Real angle); + void MakePositionAndDisplay(GEOM::GEOM_Shape_ptr ShapePtr1, + GEOM::GEOM_Shape_ptr ShapePtr2, + const TopoDS_Shape& Shape1, const TopoDS_Shape& Shape2, + const TopoDS_Shape& SubShape1, const TopoDS_Shape& SubShape2); void MakeMirrorAndDisplay(GEOM::GEOM_Shape_ptr Shape1, GEOM::GEOM_Shape_ptr Shape2); void MakeScaleAndDisplay(GEOM::GEOM_Shape_ptr Shape, const gp_Pnt centralPoint, const Standard_Real factor); diff --git a/src/TransformationGUI/TransformationGUI_PositionDlg.cxx b/src/TransformationGUI/TransformationGUI_PositionDlg.cxx new file mode 100644 index 000000000..1c46df3df --- /dev/null +++ b/src/TransformationGUI/TransformationGUI_PositionDlg.cxx @@ -0,0 +1,410 @@ +// GEOM GEOMGUI : GUI for Geometry component +// +// Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : TransformationGUI_PositionDlg.cxx +// Author : Lucien PIGNOLONI +// Module : GEOM +// $Header$ + +using namespace std; +#include "TransformationGUI_PositionDlg.h" + +#include "DisplayGUI.h" + +#include + +//================================================================================= +// class : TransformationGUI_PositionDlg() +// purpose : Constructs a TransformationGUI_PositionDlg 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_PositionDlg::TransformationGUI_PositionDlg(QWidget* parent, const char* name, TransformationGUI* theTransformationGUI, SALOME_Selection* Sel, Handle(AIS_InteractiveContext) ic, bool modal, WFlags fl) + :GEOMBase_Skeleton(parent, name, Sel, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu) +{ + QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_POS_POINT"))); + QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_POS_VECT"))); + QPixmap image2(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_POS_FACE"))); + QPixmap image3(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_SELECT"))); + + setCaption(tr("GEOM_POSITION_TITLE")); + + /***************************************************************/ + GroupConstructors->setTitle(tr("GEOM_POSITION")); + RadioButton1->setPixmap(image0); + RadioButton2->setPixmap(image1); + RadioButton3->setPixmap(image2); + + Group1 = new DlgRef_2Sel_QTD(this, "Group1"); + Group1->GroupBox1->setTitle(tr("GEOM_POS_VERTEX")); + Group1->TextLabel1->setText(tr("GEOM_OBJECT_I").arg("1")); + Group1->TextLabel2->setText(tr("GEOM_OBJECT_I").arg("2")); + Group1->PushButton1->setPixmap(image3); + Group1->PushButton2->setPixmap(image3); + + Layout1->addWidget(Group1, 1, 0); + /***************************************************************/ + + /* Initialisations */ + myTransformationGUI = theTransformationGUI; + Init(ic); +} + + +//================================================================================= +// function : ~TransformationGUI_PositionDlg() +// purpose : Destroys the object and frees any allocated resources +//================================================================================= +TransformationGUI_PositionDlg::~TransformationGUI_PositionDlg() +{ + // no need to delete child widgets, Qt does it all for us +} + + +//================================================================================= +// function : Init() +// purpose : +//================================================================================= +void TransformationGUI_PositionDlg::Init(Handle (AIS_InteractiveContext) ic) +{ + /* init variables */ + myConstructorId = 0; + myShapeType = 7; + myEditCurrentArgument = Group1->LineEdit1; + + myOkBase1 = myOkBase2 = myOkObj1 = myOkObj2 = false; + myIC = ic; + myLocalContextId = -1; + myUseLocalContext = false; + + /* signals and slots connections */ + connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel())); + connect(myGeomGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog())); + connect(myGeomGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel())); + + connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk())); + connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply())); + connect(GroupConstructors, SIGNAL(clicked(int)), this, SLOT(ConstructorsClicked(int))); + + connect(Group1->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument())); + connect(Group1->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument())); + + connect(Group1->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed())); + connect(Group1->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed())); + + connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ; + + /* displays Dialog */ + Group1->show(); + this->show(); + + return; +} + + +//================================================================================= +// function : ConstructorsClicked() +// purpose : Radio button management +//================================================================================= +void TransformationGUI_PositionDlg::ConstructorsClicked(int constructorId) +{ + resize(0, 0); + myConstructorId = constructorId; + disconnect(mySelection, 0, this, 0); + myOkBase1 = myOkBase2 = myOkObj1 = myOkObj2 = false; + myEditCurrentArgument = Group1->LineEdit1; + Group1->LineEdit1->setText(""); + Group1->LineEdit2->setText(""); + + if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_OCC && myUseLocalContext) { + myIC->CloseLocalContext(myLocalContextId); + DisplayGUI* myDisplayGUI = new DisplayGUI(); + myDisplayGUI->OnDisplayAll(true); + myUseLocalContext = false; + } + + connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())); + + if(constructorId == 0) { + Group1->GroupBox1->setTitle(tr("GEOM_POS_VERTEX")); + myShapeType = 7; //Vertex + } + else if(constructorId == 1) { + Group1->GroupBox1->setTitle(tr("GEOM_POS_EDGE")); + myShapeType = 6; //Edge + } + else if(constructorId == 2) { + Group1->GroupBox1->setTitle(tr("GEOM_POS_FACE")); + myShapeType = 4; //Face + } + + return; +} + + +//================================================================================= +// function : ClickOnOk() +// purpose : +//================================================================================= +void TransformationGUI_PositionDlg::ClickOnOk() +{ + this->ClickOnApply(); + this->ClickOnCancel(); + return; +} + + +//================================================================================= +// function : ClickOnApply() +// purpose : +//================================================================================= +void TransformationGUI_PositionDlg::ClickOnApply() +{ + QAD_Application::getDesktop()->putInfo(tr("")); + + if(myEditCurrentArgument == Group1->LineEdit2 && myUseLocalContext) { + if(myOkBase2) { + myIC->InitSelected(); + if(myIC->NbSelected() == 1) { + myIC->InitSelected(); + myIC->MoreSelected(); + myObj2 = myIC->SelectedShape(); + myOkObj2 = true; + } + } + } + else if(myEditCurrentArgument == Group1->LineEdit1 && myUseLocalContext) { + if(myOkBase1) { + myIC->InitSelected(); + if(myIC->NbSelected() == 1) { + myIC->InitSelected(); + myIC->MoreSelected(); + myObj1 = myIC->SelectedShape(); + myOkObj1 = true; + } + } + } + + if(myOkBase1 && myOkBase2 && myOkObj1 && myOkObj2) + myTransformationGUI->MakePositionAndDisplay(myGeomShape1, myGeomShape2, myShape1, myShape2, myObj1, myObj2); + + this->ResetStateOfDialog(); + return; +} + + +//================================================================================= +// function : ClickOnCancel() +// purpose : +//================================================================================= +void TransformationGUI_PositionDlg::ClickOnCancel() +{ + this->ResetStateOfDialog(); + GEOMBase_Skeleton::ClickOnCancel(); + return; +} + + +//================================================================================= +// function : SelectionIntoArgument() +// purpose : Called when selection as changed or other case +//================================================================================= +void TransformationGUI_PositionDlg::SelectionIntoArgument() +{ + if(myEditCurrentArgument == Group1->LineEdit1 && myUseLocalContext) { + if(myOkBase2) { + myIC->InitSelected(); + if(myIC->NbSelected() == 1) { + myIC->InitSelected(); + myIC->MoreSelected(); + myObj2 = myIC->SelectedShape(); + myOkObj2 = true; + } + } + } + else if(myEditCurrentArgument == Group1->LineEdit2 && myUseLocalContext) { + if(myOkBase1) { + myIC->InitSelected(); + if(myIC->NbSelected() == 1) { + myIC->InitSelected(); + myIC->MoreSelected(); + myObj1 = myIC->SelectedShape(); + myOkObj1 = true; + } + } + } + + this->ResetStateOfDialog(); + myEditCurrentArgument->setText(""); + QString aString = ""; /* name of selection */ + + int nbSel = myGeomBase->GetNameOfSelectedIObjects(mySelection, aString); + if(nbSel != 1) + return; + + // nbSel == 1 + TopoDS_Shape S; + Standard_Boolean testResult; + Handle(SALOME_InteractiveObject) IO = mySelection->firstIObject(); + if(!myGeomBase->GetTopoFromSelection(mySelection, S)) + return; + + if(myEditCurrentArgument == Group1->LineEdit1) { + myShape1 = S; + myGeomShape1 = myGeomBase->ConvertIOinGEOMShape(IO, testResult); + if(!testResult) + return; + myEditCurrentArgument->setText(aString); + myOkBase1 = true; + } + else if(myEditCurrentArgument == Group1->LineEdit2) { + myShape2 = S; + myGeomShape2 = myGeomBase->ConvertIOinGEOMShape(IO, testResult); + if(!testResult) + return; + myEditCurrentArgument->setText(aString); + myOkBase2 = true; + } + + /* local context is defined into the method */ + DisplayGUI* myDisplayGUI = new DisplayGUI(); + myDisplayGUI->PrepareSubShapeSelection(myShapeType, myLocalContextId); + myUseLocalContext = true; + + return; +} + + +//================================================================================= +// function : SetEditCurrentArgument() +// purpose : +//================================================================================= +void TransformationGUI_PositionDlg::SetEditCurrentArgument() +{ + QPushButton* send = (QPushButton*)sender(); + + if(send == Group1->PushButton1) { + Group1->LineEdit1->setFocus(); + myEditCurrentArgument = Group1->LineEdit1; + myOkBase1 = false; + myOkObj1 = false; + } + else if(send == Group1->PushButton2) { + Group1->LineEdit2->setFocus(); + myEditCurrentArgument = Group1->LineEdit2; + myOkBase2 = false; + myOkObj2 = false; + } + mySelection->ClearIObjects(); + this->SelectionIntoArgument(); + + return; +} + + +//================================================================================= +// function : LineEditReturnPressed() +// purpose : +//================================================================================= +void TransformationGUI_PositionDlg::LineEditReturnPressed() +{ + QLineEdit* send = (QLineEdit*)sender(); + if(send == Group1->LineEdit1) + myEditCurrentArgument = Group1->LineEdit1; + else if (send == Group1->LineEdit2) + myEditCurrentArgument = Group1->LineEdit2; + else + return; + + GEOMBase_Skeleton::LineEditReturnPressed(); + return; +} + + +//================================================================================= +// function : DeactivateActiveDialog() +// purpose : +//================================================================================= +void TransformationGUI_PositionDlg::DeactivateActiveDialog() +{ + this->ResetStateOfDialog(); + GEOMBase_Skeleton::DeactivateActiveDialog(); + return; +} + + +//================================================================================= +// function : ActivateThisDialog() +// purpose : +//================================================================================= +void TransformationGUI_PositionDlg::ActivateThisDialog() +{ + GEOMBase_Skeleton::ActivateThisDialog(); + connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())); + Group1->LineEdit1->setFocus(); + myEditCurrentArgument = Group1->LineEdit1; + return; +} + + +//================================================================================= +// function : enterEvent() +// purpose : +//================================================================================= +void TransformationGUI_PositionDlg::enterEvent(QEvent* e) +{ + if (GroupConstructors->isEnabled()) + return; + this->ActivateThisDialog(); + return; +} + + +//================================================================================= +// function : closeEvent() +// purpose : +//================================================================================= +void TransformationGUI_PositionDlg::closeEvent(QCloseEvent* e) +{ + /* same than click on cancel button */ + this->ClickOnCancel(); + return; +} + + +//================================================================================= +// function : ResetStateOfDialog() +// purpose : +//================================================================================= +void TransformationGUI_PositionDlg::ResetStateOfDialog() +{ + /* Close its local contact if opened */ + if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_OCC && myUseLocalContext) { + myIC->CloseLocalContext(myLocalContextId); + myUseLocalContext = false; + DisplayGUI* myDisplayGUI = new DisplayGUI(); + myDisplayGUI->OnDisplayAll(); + } + return; +} diff --git a/src/TransformationGUI/TransformationGUI_PositionDlg.h b/src/TransformationGUI/TransformationGUI_PositionDlg.h new file mode 100644 index 000000000..5fca4a6e2 --- /dev/null +++ b/src/TransformationGUI/TransformationGUI_PositionDlg.h @@ -0,0 +1,91 @@ +// GEOM GEOMGUI : GUI for Geometry component +// +// Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : TransformationGUI_PositionDlg.h +// Author : Lucien PIGNOLONI +// Module : GEOM +// $Header$ + +#ifndef DIALOGBOX_POSITION_H +#define DIALOGBOX_POSITION_H + +#include "GEOMBase_Skeleton.h" +#include "DlgRef_2Sel_QTD.h" + +#include "TransformationGUI.h" + +//================================================================================= +// class : TransformationGUI_PositionDlg +// purpose : +//================================================================================= +class TransformationGUI_PositionDlg : public GEOMBase_Skeleton +{ + Q_OBJECT + +public: + TransformationGUI_PositionDlg(QWidget* parent = 0, const char* name = 0, TransformationGUI* theTransformationGUI = 0, SALOME_Selection* Sel = 0, Handle(AIS_InteractiveContext) ic = 0, bool modal = FALSE, WFlags fl = 0); + ~TransformationGUI_PositionDlg(); + +private : + void Init(Handle(AIS_InteractiveContext) ic); + void enterEvent(QEvent* e); + void closeEvent(QCloseEvent* e); + void ResetStateOfDialog(); + + TransformationGUI* myTransformationGUI; + + int myConstructorId; /* Current constructor id = radio button id */ + + /* Interactive and local context management see also : bool myUseLocalContext() */ + Handle(AIS_InteractiveContext) myIC; /* Interactive context */ + Standard_Integer myLocalContextId; /* identify a local context used by this method */ + bool myUseLocalContext; /* true when this method as opened a local context */ + + TopoDS_Shape myShape1; + TopoDS_Shape myShape2; + TopoDS_Shape myObj1; + TopoDS_Shape myObj2; + int myShapeType; + GEOM::GEOM_Shape_var myGeomShape1; + GEOM::GEOM_Shape_var myGeomShape2; + bool myOkBase1; + bool myOkBase2; + bool myOkObj1; + bool myOkObj2; + + DlgRef_2Sel_QTD* Group1; + +private slots: + void ClickOnOk(); + void ClickOnApply(); + void ClickOnCancel(); + void ActivateThisDialog(); + void DeactivateActiveDialog(); + void LineEditReturnPressed(); + void SelectionIntoArgument(); + void SetEditCurrentArgument(); + void ConstructorsClicked(int constructorId); + +}; + +#endif // DIALOGBOX_POSITION_H -- 2.39.2