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 : MeasureGUI_DistanceDlg.cxx
25 // Author : Nicolas REJNERI
29 #include "MeasureGUI_DistanceDlg.h"
31 #include "QAD_RightFrame.h"
32 #include "OCCViewer_Viewer3d.h"
34 #include <Geom_Plane.hxx>
35 #include <TopoDS_Edge.hxx>
36 #include <BRepExtrema_DistShapeShape.hxx>
37 #include <AIS_LengthDimension.hxx>
38 #include <BRepBuilderAPI_MakeEdge.hxx>
39 #include <BRepBuilderAPI_MakeVertex.hxx>
40 #include <AIS_ListIteratorOfListOfInteractive.hxx>
41 #include <gce_MakePln.hxx>
42 #include <Precision.hxx>
44 #include "utilities.h"
48 //=================================================================================
49 // class : MeasureGUI_DistanceDlg()
50 // purpose : Constructs a MeasureGUI_DistanceDlg which is a child of 'parent', with the
51 // name 'name' and widget flags set to 'f'.
52 // The dialog will by default be modeless, unless you set 'modal' to
53 // TRUE to construct a modal dialog.
54 //=================================================================================
55 MeasureGUI_DistanceDlg::MeasureGUI_DistanceDlg(QWidget* parent, const char* name, SALOME_Selection* Sel, bool modal, WFlags fl)
56 :MeasureGUI_Skeleton(parent, name, Sel, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
58 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_MINDIST")));
59 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_SELECT")));
61 setCaption(tr("GEOM_MINDIST_TITLE"));
63 /***************************************************************/
64 GroupConstructors->setTitle(tr("GEOM_DISTANCE"));
65 RadioButton1->setPixmap(image0);
67 GroupC1 = new MeasureGUI_2Sel1LineEdit_QTD(this, "GroupC1");
68 GroupC1->GroupBox1->setTitle(tr("GEOM_MINDIST_OBJ"));
69 GroupC1->TextLabel1->setText(tr("GEOM_OBJECT_I").arg("1"));
70 GroupC1->TextLabel2->setText(tr("GEOM_OBJECT_I").arg("2"));
71 GroupC1->TextLabel3->setText(tr("GEOM_LENGTH"));
72 GroupC1->LineEdit3->setReadOnly(TRUE);
73 GroupC1->PushButton1->setPixmap(image1);
74 GroupC1->PushButton2->setPixmap(image1);
76 Layout1->addWidget(GroupC1, 1, 0);
77 /***************************************************************/
84 //=================================================================================
85 // function : ~MeasureGUI_DistanceDlg()
86 // purpose : Destroys the object and frees any allocated resources
87 //=================================================================================
88 MeasureGUI_DistanceDlg::~MeasureGUI_DistanceDlg()
90 /* no need to delete child widgets, Qt does it all for us */
94 //=================================================================================
97 //=================================================================================
98 void MeasureGUI_DistanceDlg::Init()
101 myEditCurrentArgument = GroupC1->LineEdit1;
103 myOkShape1 = myOkShape2 = false;
105 /* signals and slots connections */
106 connect(buttonClose, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
107 connect(myGeomGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
108 connect(myGeomGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
110 connect(GroupC1->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
111 connect(GroupC1->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
113 connect(GroupC1->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
114 connect(GroupC1->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
116 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
118 /* displays Dialog */
126 //=================================================================================
127 // function : ClickOnCancel()
129 //=================================================================================
130 void MeasureGUI_DistanceDlg::ClickOnCancel()
132 this->EraseDistance();
133 MeasureGUI_Skeleton::ClickOnCancel();
138 //=================================================================================
139 // function : SelectionIntoArgument()
140 // purpose : Called when selection has changed
141 //=================================================================================
142 void MeasureGUI_DistanceDlg::SelectionIntoArgument()
144 myGeomBase->EraseSimulationShape();
145 mySimulationTopoDs.Nullify();
146 this->EraseDistance();
147 myEditCurrentArgument->setText("");
148 QString aString = "";
150 GroupC1->LineEdit3->setText("");
152 int nbSel = myGeomBase->GetNameOfSelectedIObjects(mySelection, aString);
154 if(myEditCurrentArgument == GroupC1->LineEdit1)
156 else if(myEditCurrentArgument == GroupC1->LineEdit2)
163 if(!myGeomBase->GetTopoFromSelection(mySelection, S))
166 Standard_Boolean testResult;
167 Handle(SALOME_InteractiveObject) IO = mySelection->firstIObject();
169 if(myEditCurrentArgument == GroupC1->LineEdit1) {
170 myGeomShape1 = myGeomBase->ConvertIOinGEOMShape(IO, testResult);
174 myEditCurrentArgument->setText(aString);
177 else if(myEditCurrentArgument == GroupC1->LineEdit2) {
178 myGeomShape2 = myGeomBase->ConvertIOinGEOMShape(IO, testResult);
182 myEditCurrentArgument->setText(aString);
186 if(myOkShape1 && myOkShape2)
187 this->MakeDistanceSimulationAndDisplay(myShape1 ,myShape2);
192 //=================================================================================
193 // function : SetEditCurrentArgument()
195 //=================================================================================
196 void MeasureGUI_DistanceDlg::SetEditCurrentArgument()
198 QPushButton* send = (QPushButton*)sender();
200 if(send == GroupC1->PushButton1) {
201 GroupC1->LineEdit1->setFocus();
202 myEditCurrentArgument = GroupC1->LineEdit1;
204 else if(send == GroupC1->PushButton2) {
205 GroupC1->LineEdit2->setFocus();
206 myEditCurrentArgument = GroupC1->LineEdit2;
209 this->SelectionIntoArgument();
214 //=================================================================================
215 // function : LineEditReturnPressed()
217 //=================================================================================
218 void MeasureGUI_DistanceDlg::LineEditReturnPressed()
220 QLineEdit* send = (QLineEdit*)sender();
221 if(send == GroupC1->LineEdit1)
222 myEditCurrentArgument = GroupC1->LineEdit1;
223 else if(send == GroupC1->LineEdit2)
224 myEditCurrentArgument = GroupC1->LineEdit2;
228 MeasureGUI_Skeleton::LineEditReturnPressed();
233 //=================================================================================
234 // function : ActivateThisDialog()
236 //=================================================================================
237 void MeasureGUI_DistanceDlg::ActivateThisDialog()
239 MeasureGUI_Skeleton::ActivateThisDialog();
240 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
241 if(!mySimulationTopoDs.IsNull())
242 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
247 //=================================================================================
248 // function : enterEvent()
249 // purpose : when mouse enter onto the QWidget
250 //=================================================================================
251 void MeasureGUI_DistanceDlg::enterEvent(QEvent* e)
253 if(GroupConstructors->isEnabled())
255 this->ActivateThisDialog();
260 //=================================================================================
261 // function : closeEvent()
263 //=================================================================================
264 void MeasureGUI_DistanceDlg::closeEvent(QCloseEvent* e)
266 /* same than click on cancel button */
267 this->ClickOnCancel();
272 //=================================================================================
273 // function : MakeDistanceSimulationAndDisplay()
275 //=================================================================================
276 void MeasureGUI_DistanceDlg::MakeDistanceSimulationAndDisplay(const TopoDS_Shape& S1, const TopoDS_Shape& S2)
278 myGeomBase->EraseSimulationShape();
279 mySimulationTopoDs.Nullify();
280 GroupC1->LineEdit3->setText("");
282 BRepExtrema_DistShapeShape dst(S1, S2);
287 Standard_Real Dist = 1.e9;
288 for(int i = 1; i <= dst.NbSolution(); i++) {
289 P1 = (dst.PointOnShape1(i));
290 P2 = (dst.PointOnShape2(i));
292 Standard_Real MinDist = P1.Distance(P2);
298 BRepBuilderAPI_MakeVertex MakeVertex(P1);
299 mySimulationTopoDs = MakeVertex.Vertex();
300 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
302 GroupC1->LineEdit3->setText("0.0");
305 BRepBuilderAPI_MakeEdge MakeEdge(P1, P2);
306 mySimulationTopoDs = MakeEdge.Edge();
308 TopoDS_Vertex V1 = BRepBuilderAPI_MakeVertex(P1);
309 TopoDS_Vertex V2 = BRepBuilderAPI_MakeVertex(P2);
312 S.sprintf("%.1f", Dist);
315 P3.SetX((P1.X() + P2.X()) / 2);
316 P3.SetY((P1.Y() + P2.Y()) / 2);
317 P3.SetZ(((P1.Z() + P2.Z()) / 2) + 100);
320 if(va.IsParallel(vb, Precision::Angular())) {
321 P3.SetY(((P1.Y() + P2.Y()) / 2) + 100);
322 P3.SetZ(((P1.Z() + P2.Z()) / 2));
324 gce_MakePln gce_MP(P1, P2, P3);
325 gp_Pln gp_P = gce_MP.Value();
326 Handle(Geom_Plane) P = new Geom_Plane(gp_P);
328 char* aCopyS = CORBA::string_dup(S);
329 Handle(AIS_LengthDimension) Distance = new AIS_LengthDimension(V1, V2, P, Dist, TCollection_ExtendedString(aCopyS));
332 GroupC1->LineEdit3->setText(S);
334 if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_OCC) {
335 OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer();
336 Handle (AIS_InteractiveContext) ic = v3d->getAISContext();
337 ic->Display(Distance);
338 ic->UpdateCurrentViewer();
343 catch(Standard_Failure) {
344 MESSAGE("Catch intercepted in MakeDistanceSimulationAndDisplay()");
350 //=================================================================================
351 // function : EraseDistance()
353 //=================================================================================
354 void MeasureGUI_DistanceDlg::EraseDistance()
356 int count = QAD_Application::getDesktop()->getActiveStudy()->getStudyFramesCount();
357 for(int i = 0; i < count; i++) {
358 if (QAD_Application::getDesktop()->getActiveStudy()->getStudyFrame(i)->getTypeView() == VIEW_OCC ) {
359 OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getStudyFrame(i)->getRightFrame()->getViewFrame())->getViewer();
360 Handle (AIS_InteractiveContext) ic = v3d->getAISContext();
362 AIS_ListOfInteractive L;
363 ic->DisplayedObjects(AIS_KOI_Relation, -1, L);
364 AIS_ListIteratorOfListOfInteractive ite(L);
366 ic->Remove(ite.Value());
367 ic->UpdateCurrentViewer();