1 // GEOM GEOMGUI : GUI for Geometry component
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : BasicGUI.cxx
25 // Author : Damien COQUERET
32 #include "QAD_RightFrame.h"
33 #include "OCCViewer_Viewer3d.h"
34 #include "OCCViewer_ViewPort3d.h"
35 #include "SALOMEGUI_QtCatchCorbaException.hxx"
37 #include <Precision.hxx>
38 #include <BRep_Tool.hxx>
39 #include <ProjLib.hxx>
42 #include "BasicGUI_PointDlg.h" // Method POINT
43 #include "BasicGUI_LineDlg.h" // Method LINE
44 #include "BasicGUI_CircleDlg.h" // Method CIRCLE
45 #include "BasicGUI_EllipseDlg.h" // Method ELLIPSE
46 #include "BasicGUI_ArcDlg.h" // Method ARC
47 #include "BasicGUI_VectorDlg.h" // Method VECTOR
48 #include "BasicGUI_PlaneDlg.h" // Method PLANE
49 #include "BasicGUI_WorkingPlaneDlg.h" // Method WORKING PLANE
51 //=======================================================================
52 // function : BasicGUI()
53 // purpose : Constructor
54 //=======================================================================
55 BasicGUI::BasicGUI() :
58 myGeomBase = new GEOMBase();
59 myGeomGUI = GEOMContext::GetGeomGUI();
60 myGeom = myGeomGUI->myComponentGeom;
64 //=======================================================================
65 // function : ~BasicGUI()
66 // purpose : Destructor
67 //=======================================================================
73 //=======================================================================
74 // function : OnGUIEvent()
76 //=======================================================================
77 bool BasicGUI::OnGUIEvent(int theCommandID, QAD_Desktop* parent)
79 BasicGUI* myBasicGUI = new BasicGUI();
80 myBasicGUI->myGeomGUI->EmitSignalDeactivateDialog();
81 SALOME_Selection* Sel = SALOME_Selection::Selection(QAD_Application::getDesktop()->getActiveStudy()->getSelection());
87 Handle(AIS_InteractiveContext) ic;
88 if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_OCC) {
89 OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer();
90 ic = v3d->getAISContext();
92 BasicGUI_PointDlg *aDlg = new BasicGUI_PointDlg(parent, "", myBasicGUI, Sel, ic);
97 BasicGUI_LineDlg *aDlg = new BasicGUI_LineDlg(parent, "", myBasicGUI, Sel);
102 BasicGUI_CircleDlg *aDlg = new BasicGUI_CircleDlg(parent, "", myBasicGUI, Sel);
105 case 4014: // ELLIPSE
107 BasicGUI_EllipseDlg *aDlg = new BasicGUI_EllipseDlg(parent, "", myBasicGUI, Sel);
112 BasicGUI_ArcDlg *aDlg = new BasicGUI_ArcDlg(parent, "", myBasicGUI, Sel);
117 BasicGUI_VectorDlg *aDlg = new BasicGUI_VectorDlg(parent, "", myBasicGUI, Sel);
122 BasicGUI_PlaneDlg *aDlg = new BasicGUI_PlaneDlg(parent, "", myBasicGUI, Sel);
125 case 4018: // WORKING PLANE
127 BasicGUI_WorkingPlaneDlg *aDlg = new BasicGUI_WorkingPlaneDlg(parent, "", myBasicGUI, Sel);
132 parent->putInfo(tr("GEOM_PRP_COMMAND").arg(theCommandID));
140 //=================================================================================
141 // function : 0nMousePress()
142 // purpose : [static] manage mouse events
143 //=================================================================================
144 bool BasicGUI::OnMousePress(QMouseEvent* pe, QAD_Desktop* parent, QAD_StudyFrame* studyFrame)
146 BasicGUI* myBasicGUI = new BasicGUI();
148 if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() > VIEW_OCC)
151 OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer();
152 Handle (AIS_InteractiveContext) ic = v3d->getAISContext();
153 OCCViewer_ViewPort* vp = ((OCCViewer_ViewFrame*)studyFrame->getRightFrame()->getViewFrame())->getViewPort();
155 /* Get the clicked or selected point */
158 myBasicGUI->myGeomBase->EraseSimulationShape();
159 BasicGUI_PointDlg *DialogPt = (BasicGUI_PointDlg*)(myBasicGUI->myGeomGUI->GetActiveDialogBox());
161 if(DialogPt->UseLocalContext()) {
163 if(pe->state() == Qt::ShiftButton)
164 v3d->getAISSelector()->shiftSelect(); /* Append selection */
166 v3d->getAISSelector()->select(); /* New selection */
169 if(ic->MoreSelected())
170 thePoint = BRep_Tool::Pnt(TopoDS::Vertex(ic->SelectedShape()));
172 thePoint = myBasicGUI->ConvertClickToPoint(pe->x(), pe->y(), ((OCCViewer_ViewPort3d*)vp)->getView());
175 thePoint = myBasicGUI->ConvertClickToPoint(pe->x(), pe->y(), ((OCCViewer_ViewPort3d*)vp)->getView());
178 DialogPt->PointIntoCoordinates(thePoint, true); /* display point */
180 QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_ABORT"));
186 //=======================================================================
187 // function : ConvertClickToPoint()
188 // purpose : Returns the point clicked in 3D view
189 //=======================================================================
190 gp_Pnt BasicGUI::ConvertClickToPoint(Standard_Real x, Standard_Real y, Handle(V3d_View) aView)
192 V3d_Coordinate XEye, YEye, ZEye, XAt, YAt, ZAt;
193 aView->Eye(XEye, YEye, ZEye);
195 aView->At(XAt, YAt, ZAt);
196 gp_Pnt EyePoint(XEye, YEye, ZEye);
197 gp_Pnt AtPoint(XAt, YAt, ZAt);
199 gp_Vec EyeVector(EyePoint, AtPoint);
200 gp_Dir EyeDir(EyeVector);
202 gp_Pln PlaneOfTheView = gp_Pln(AtPoint,EyeDir);
203 Standard_Real X, Y, Z;
204 aView->Convert(x, y, X, Y, Z);
205 gp_Pnt ConvertedPoint(X, Y, Z);
207 gp_Pnt2d ConvertedPointOnPlane = ProjLib::Project(PlaneOfTheView, ConvertedPoint);
208 gp_Pnt ResultPoint = ElSLib::Value(ConvertedPointOnPlane.X(), ConvertedPointOnPlane.Y(), PlaneOfTheView);
213 //=======================================================================
214 // function : MakePointAndDisplay
216 //=======================================================================
217 void BasicGUI::MakePointAndDisplay(const double x, const double y, const double z)
220 GEOM::GEOM_Shape_var P = myGeom->MakeVertex(x, y, z);
221 P->NameType(tr("GEOM_VERTEX"));
222 if (myGeomBase->Display(P))
223 QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_DONE"));
225 catch(const SALOME::SALOME_Exception& S_ex) {
226 QtCatchCorbaException(S_ex);
232 //=====================================================================================
233 // function : MakeLineAndDisplay()
234 // purpose : Create an infinite oriented line (linear edge in fact)
235 //=====================================================================================
236 void BasicGUI::MakeLineAndDisplay(const gp_Pnt InitPoint, const gp_Pnt LastPoint)
240 myGeomBase->GetBipointDxDyDz(InitPoint, LastPoint, dx, dy, dz);
241 Standard_Real length = InitPoint.Distance(LastPoint);
242 if(length <= Precision::Confusion()) {
243 QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_ABORT"));
247 Standard_Real coeff = 1E6 / length;
249 /* To create a line with length = 1E6 */
250 /* Precision::Infinite() is 1E100 in OCC */
251 P1.SetX(InitPoint.X() - (coeff * dx));
252 P1.SetY(InitPoint.Y() - (coeff * dy));
253 P1.SetZ(InitPoint.Z() - (coeff * dz));
255 P2.SetX(LastPoint.X() + (coeff * dx));
256 P2.SetY(LastPoint.Y() + (coeff * dy));
257 P2.SetZ(LastPoint.Z() + (coeff * dz));
260 GEOM::PointStruct pstruct = myGeom->MakePointStruct(P1.X(), P1.Y(), P1.Z());
261 GEOM::PointStruct d = myGeom->MakePointStruct(P2.X(), P2.Y(), P2.Z());
262 GEOM::DirStruct dstruct = myGeom->MakeDirection(d);
264 GEOM::GEOM_Shape_ptr result = myGeom->MakeLine(pstruct, dstruct);
265 if(result->_is_nil()) {
266 QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_ABORT"));
269 result->NameType(tr("GEOM_LINE"));
271 if(myGeomBase->Display(result))
272 QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_READY"));
274 catch(const SALOME::SALOME_Exception& S_ex) {
275 QtCatchCorbaException(S_ex);
281 //=====================================================================================
282 // function : MakeCircleAndDisplay()
284 //=====================================================================================
285 void BasicGUI::MakeCircleAndDisplay(const gp_Pnt CenterPoint, const gp_Dir dir, const Standard_Real Radius)
288 GEOM::PointStruct pstruct = myGeom->MakePointStruct(CenterPoint.X(), CenterPoint.Y(), CenterPoint.Z());
289 GEOM::PointStruct d = myGeom->MakePointStruct(dir.X(), dir.Y(), dir.Z());
290 GEOM::DirStruct dstruct = myGeom->MakeDirection(d);
292 GEOM::GEOM_Shape_var result = myGeom->MakeCircle(pstruct, dstruct, Radius);
293 if(result->_is_nil()) {
294 QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_ABORT"));
297 result->NameType(tr("GEOM_CIRCLE"));
298 if(myGeomBase->Display(result))
299 QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_DONE"));
301 catch(const SALOME::SALOME_Exception& S_ex) {
302 QtCatchCorbaException(S_ex);
308 //=====================================================================================
309 // function : MakeEllipseAndDisplay()
311 //=====================================================================================
312 void BasicGUI::MakeEllipseAndDisplay(const gp_Pnt CenterPoint, const gp_Dir dir,
313 const Standard_Real Major_Radius, const Standard_Real Minor_Radius)
316 GEOM::PointStruct pstruct = myGeom->MakePointStruct(CenterPoint.X(), CenterPoint.Y(), CenterPoint.Z());
317 GEOM::PointStruct d = myGeom->MakePointStruct(dir.X(), dir.Y(), dir.Z());
318 GEOM::DirStruct dstruct = myGeom->MakeDirection(d) ;
320 GEOM::GEOM_Shape_var result = myGeom->MakeEllipse(pstruct, dstruct, Major_Radius, Minor_Radius);
321 if(result->_is_nil()) {
322 QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_ABORT"));
325 result->NameType(tr("GEOM_ELLIPSE"));
326 if(myGeomBase->Display(result))
327 QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_DONE"));
329 catch(const SALOME::SALOME_Exception& S_ex) {
330 QtCatchCorbaException(S_ex);
336 //=======================================================================================
337 // function : MakeArcAndDisplay()
338 // purpose : Make an arc of circle from InitPoint to CirclePoint and passing on EndPoint
339 //=======================================================================================
340 void BasicGUI::MakeArcAndDisplay(gp_Pnt InitPoint, gp_Pnt CirclePoint, gp_Pnt EndPoint)
342 gp_Vec v1(CirclePoint, InitPoint);
343 gp_Vec v2(CirclePoint, EndPoint);
344 if(v1.IsParallel(v2, Precision::Angular()))
348 GEOM::PointStruct pI = myGeom->MakePointStruct(InitPoint.X(), InitPoint.Y(), InitPoint.Z());
349 GEOM::PointStruct pC = myGeom->MakePointStruct(CirclePoint.X(), CirclePoint.Y(), CirclePoint.Z());
350 GEOM::PointStruct pE = myGeom->MakePointStruct(EndPoint.X(), EndPoint.Y(), EndPoint.Z());
351 GEOM::GEOM_Shape_var result = myGeom->MakeArc(pI, pC, pE);
352 if(result->_is_nil()) {
353 QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_ABORT"));
356 result->NameType(tr("GEOM_ARC"));
357 if (myGeomBase->Display(result))
358 QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_DONE"));
360 catch(const SALOME::SALOME_Exception& S_ex) {
361 QtCatchCorbaException(S_ex);
367 //=======================================================================
368 // function : MakeVectorAndDisplay()
370 //=======================================================================
371 void BasicGUI::MakeVectorAndDisplay(const gp_Pnt P1, const gp_Pnt P2)
374 GEOM::PointStruct pstruct1 = myGeom->MakePointStruct(P1.X(), P1.Y(), P1.Z());
375 GEOM::PointStruct pstruct2 = myGeom->MakePointStruct(P2.X(), P2.Y(), P2.Z());
376 GEOM::GEOM_Shape_var Vector = myGeom->MakeVector(pstruct1, pstruct2);
377 Vector->NameType(tr("GEOM_VECTOR"));
378 if(myGeomBase->Display(Vector))
379 QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_DONE"));
381 catch(const SALOME::SALOME_Exception& S_ex) {
382 QtCatchCorbaException(S_ex);
388 //=======================================================================
389 // function : MakePlaneAndDisplay()
390 // purpose : Plane point is P1 and dx, dy, dz define a normal vector
391 //=======================================================================
392 void BasicGUI::MakePlaneAndDisplay(const gp_Pnt P1, const Standard_Real dx, const Standard_Real dy,
393 const Standard_Real dz, const Standard_Real TrimSize)
397 aDirection.SetCoord(dx, dy, dz);
398 gp_Ax2 Axis(P1, aDirection);
400 GEOM::PointStruct pstruct = myGeom->MakePointStruct(P1.X(), P1.Y(), P1.Z());
401 GEOM::PointStruct d = myGeom->MakePointStruct(aDirection.X(), aDirection.Y(), aDirection.Z());
402 GEOM::DirStruct dstruct = myGeom->MakeDirection(d);
403 GEOM::GEOM_Shape_ptr plane = myGeom->MakePlane(pstruct, dstruct, TrimSize);
404 plane->NameType(tr("GEOM_PLANE"));
405 if(myGeomBase->Display(plane))
406 QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_DONE"));
408 catch(const SALOME::SALOME_Exception& S_ex) {
409 QtCatchCorbaException(S_ex);
415 //=======================================================================
416 // function : MakeWorkingPlane()
417 // purpose : Change the point of view3d
418 //=======================================================================
419 void BasicGUI::MakeWorkingPlane(const gp_Pnt P, const gp_Dir D)
421 if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() != VIEW_OCC) {
422 QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_NOT_FOR_VTK_VIEWER"));
426 OCCViewer_ViewPort* vp = ((OCCViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewPort();
427 Handle(V3d_View) view3d = ((OCCViewer_ViewPort3d*)vp)->getView();
428 view3d->SetAt(P.X(), P.Y(), P.Z());
429 view3d->SetProj(D.X(), D.Y(), D.Z());
430 QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_DONE"));
435 //=====================================================================================
437 //=====================================================================================
440 bool OnGUIEvent(int theCommandID, QAD_Desktop* parent)
441 {return BasicGUI::OnGUIEvent(theCommandID, parent);}
443 bool OnMousePress(QMouseEvent* pe, QAD_Desktop* parent, QAD_StudyFrame* studyFrame)
444 {return BasicGUI::OnMousePress(pe, parent, studyFrame);}