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
30 #include "MeasureGUI_DistanceDlg.h"
32 #include "QAD_RightFrame.h"
33 #include "OCCViewer_Viewer3d.h"
35 #include <Geom_Plane.hxx>
36 #include <TopoDS_Edge.hxx>
37 #include <BRepExtrema_DistShapeShape.hxx>
38 #include <AIS_LengthDimension.hxx>
39 #include <BRepBuilderAPI_MakeEdge.hxx>
40 #include <BRepBuilderAPI_MakeVertex.hxx>
41 #include <AIS_ListIteratorOfListOfInteractive.hxx>
42 #include <gce_MakePln.hxx>
43 #include <Precision.hxx>
45 //=================================================================================
46 // class : MeasureGUI_DistanceDlg()
47 // purpose : Constructs a MeasureGUI_DistanceDlg which is a child of 'parent', with the
48 // name 'name' and widget flags set to 'f'.
49 // The dialog will by default be modeless, unless you set 'modal' to
50 // TRUE to construct a modal dialog.
51 //=================================================================================
52 MeasureGUI_DistanceDlg::MeasureGUI_DistanceDlg(QWidget* parent, const char* name, SALOME_Selection* Sel, bool modal, WFlags fl)
53 :MeasureGUI_Skeleton(parent, name, Sel, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
55 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_MINDIST")));
56 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_SELECT")));
58 setCaption(tr("GEOM_MINDIST_TITLE"));
60 /***************************************************************/
61 GroupConstructors->setTitle(tr("GEOM_DISTANCE"));
62 RadioButton1->setPixmap(image0);
64 GroupC1 = new MeasureGUI_2Sel1LineEdit_QTD(this, "GroupC1");
65 GroupC1->GroupBox1->setTitle(tr("GEOM_MINDIST_OBJ"));
66 GroupC1->TextLabel1->setText(tr("GEOM_OBJECT_I").arg("1"));
67 GroupC1->TextLabel2->setText(tr("GEOM_OBJECT_I").arg("2"));
68 GroupC1->TextLabel3->setText(tr("GEOM_LENGTH"));
69 GroupC1->LineEdit3->setReadOnly(TRUE);
70 GroupC1->PushButton1->setPixmap(image1);
71 GroupC1->PushButton2->setPixmap(image1);
73 Layout1->addWidget(GroupC1, 1, 0);
74 /***************************************************************/
81 //=================================================================================
82 // function : ~MeasureGUI_DistanceDlg()
83 // purpose : Destroys the object and frees any allocated resources
84 //=================================================================================
85 MeasureGUI_DistanceDlg::~MeasureGUI_DistanceDlg()
87 /* no need to delete child widgets, Qt does it all for us */
91 //=================================================================================
94 //=================================================================================
95 void MeasureGUI_DistanceDlg::Init()
98 myEditCurrentArgument = GroupC1->LineEdit1;
100 myOkShape1 = myOkShape2 = false;
102 /* signals and slots connections */
103 connect(buttonClose, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
104 connect(myGeomGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
105 connect(myGeomGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
107 connect(GroupC1->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
108 connect(GroupC1->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
110 connect(GroupC1->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
111 connect(GroupC1->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
113 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
115 /* displays Dialog */
123 //=================================================================================
124 // function : ClickOnCancel()
126 //=================================================================================
127 void MeasureGUI_DistanceDlg::ClickOnCancel()
129 this->EraseDistance();
130 MeasureGUI_Skeleton::ClickOnCancel();
135 //=================================================================================
136 // function : SelectionIntoArgument()
137 // purpose : Called when selection has changed
138 //=================================================================================
139 void MeasureGUI_DistanceDlg::SelectionIntoArgument()
141 myGeomBase->EraseSimulationShape();
142 mySimulationTopoDs.Nullify();
143 this->EraseDistance();
144 myEditCurrentArgument->setText("");
145 QString aString = "";
147 GroupC1->LineEdit3->setText("");
149 int nbSel = myGeomBase->GetNameOfSelectedIObjects(mySelection, aString);
151 if(myEditCurrentArgument == GroupC1->LineEdit1)
153 else if(myEditCurrentArgument == GroupC1->LineEdit2)
160 if(!myGeomBase->GetTopoFromSelection(mySelection, S))
163 Standard_Boolean testResult;
164 Handle(SALOME_InteractiveObject) IO = mySelection->firstIObject();
166 if(myEditCurrentArgument == GroupC1->LineEdit1) {
167 myGeomShape1 = myGeomBase->ConvertIOinGEOMShape(IO, testResult);
171 myEditCurrentArgument->setText(aString);
174 else if(myEditCurrentArgument == GroupC1->LineEdit2) {
175 myGeomShape2 = myGeomBase->ConvertIOinGEOMShape(IO, testResult);
179 myEditCurrentArgument->setText(aString);
183 if(myOkShape1 && myOkShape2)
184 this->MakeDistanceSimulationAndDisplay(myShape1 ,myShape2);
189 //=================================================================================
190 // function : SetEditCurrentArgument()
192 //=================================================================================
193 void MeasureGUI_DistanceDlg::SetEditCurrentArgument()
195 QPushButton* send = (QPushButton*)sender();
197 if(send == GroupC1->PushButton1) {
198 GroupC1->LineEdit1->setFocus();
199 myEditCurrentArgument = GroupC1->LineEdit1;
201 else if(send == GroupC1->PushButton2) {
202 GroupC1->LineEdit2->setFocus();
203 myEditCurrentArgument = GroupC1->LineEdit2;
206 this->SelectionIntoArgument();
211 //=================================================================================
212 // function : LineEditReturnPressed()
214 //=================================================================================
215 void MeasureGUI_DistanceDlg::LineEditReturnPressed()
217 QLineEdit* send = (QLineEdit*)sender();
218 if(send == GroupC1->LineEdit1)
219 myEditCurrentArgument = GroupC1->LineEdit1;
220 else if(send == GroupC1->LineEdit2)
221 myEditCurrentArgument = GroupC1->LineEdit2;
225 MeasureGUI_Skeleton::LineEditReturnPressed();
230 //=================================================================================
231 // function : ActivateThisDialog()
233 //=================================================================================
234 void MeasureGUI_DistanceDlg::ActivateThisDialog()
236 MeasureGUI_Skeleton::ActivateThisDialog();
237 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
238 if(!mySimulationTopoDs.IsNull())
239 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
244 //=================================================================================
245 // function : enterEvent()
246 // purpose : when mouse enter onto the QWidget
247 //=================================================================================
248 void MeasureGUI_DistanceDlg::enterEvent(QEvent* e)
250 if(GroupConstructors->isEnabled())
252 this->ActivateThisDialog();
257 //=================================================================================
258 // function : closeEvent()
260 //=================================================================================
261 void MeasureGUI_DistanceDlg::closeEvent(QCloseEvent* e)
263 /* same than click on cancel button */
264 this->ClickOnCancel();
269 //=================================================================================
270 // function : MakeDistanceSimulationAndDisplay()
272 //=================================================================================
273 void MeasureGUI_DistanceDlg::MakeDistanceSimulationAndDisplay(const TopoDS_Shape& S1, const TopoDS_Shape& S2)
275 myGeomBase->EraseSimulationShape();
276 mySimulationTopoDs.Nullify();
277 GroupC1->LineEdit3->setText("");
279 BRepExtrema_DistShapeShape dst(S1, S2);
284 Standard_Real Dist = 1.e9;
285 for(int i = 1; i <= dst.NbSolution(); i++) {
286 P1 = (dst.PointOnShape1(i));
287 P2 = (dst.PointOnShape2(i));
289 Standard_Real MinDist = P1.Distance(P2);
295 BRepBuilderAPI_MakeVertex MakeVertex(P1);
296 mySimulationTopoDs = MakeVertex.Vertex();
297 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
299 GroupC1->LineEdit3->setText("0.0");
302 BRepBuilderAPI_MakeEdge MakeEdge(P1, P2);
303 mySimulationTopoDs = MakeEdge.Edge();
305 TopoDS_Vertex V1 = BRepBuilderAPI_MakeVertex(P1);
306 TopoDS_Vertex V2 = BRepBuilderAPI_MakeVertex(P2);
309 S.sprintf("%.1f", Dist);
312 P3.SetX((P1.X() + P2.X()) / 2);
313 P3.SetY((P1.Y() + P2.Y()) / 2);
314 P3.SetZ(((P1.Z() + P2.Z()) / 2) + 100);
317 if(va.IsParallel(vb, Precision::Angular())) {
318 P3.SetY(((P1.Y() + P2.Y()) / 2) + 100);
319 P3.SetZ(((P1.Z() + P2.Z()) / 2));
321 gce_MakePln gce_MP(P1, P2, P3);
322 gp_Pln gp_P = gce_MP.Value();
323 Handle(Geom_Plane) P = new Geom_Plane(gp_P);
325 Handle(AIS_LengthDimension) Distance = new AIS_LengthDimension(V1, V2, P, Dist, TCollection_ExtendedString(strdup(S)));
327 GroupC1->LineEdit3->setText(S);
329 if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_OCC) {
330 OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer();
331 Handle (AIS_InteractiveContext) ic = v3d->getAISContext();
332 ic->Display(Distance);
333 ic->UpdateCurrentViewer();
338 catch(Standard_Failure) {
339 MESSAGE("Catch intercepted in MakeDistanceSimulationAndDisplay()");
345 //=================================================================================
346 // function : EraseDistance()
348 //=================================================================================
349 void MeasureGUI_DistanceDlg::EraseDistance()
351 int count = QAD_Application::getDesktop()->getActiveStudy()->getStudyFramesCount();
352 for(int i = 0; i < count; i++) {
353 if (QAD_Application::getDesktop()->getActiveStudy()->getStudyFrame(i)->getTypeView() == VIEW_OCC ) {
354 OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getStudyFrame(i)->getRightFrame()->getViewFrame())->getViewer();
355 Handle (AIS_InteractiveContext) ic = v3d->getAISContext();
357 AIS_ListOfInteractive L;
358 ic->DisplayedObjects(AIS_KOI_Relation, -1, L);
359 AIS_ListIteratorOfListOfInteractive ite(L);
361 ic->Remove(ite.Value());
362 ic->UpdateCurrentViewer();