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_VectorDlg.cxx
25 // Author : Lucien PIGNOLONI
30 #include "BasicGUI_VectorDlg.h"
32 #include "QAD_Config.h"
33 #include <TopoDS_Shape.hxx>
34 #include <TopoDS_Compound.hxx>
35 #include <BRepBuilderAPI_MakeEdge.hxx>
36 #include <BRep_Builder.hxx>
37 #include <Precision.hxx>
39 //=================================================================================
40 // class : BasicGUI_VectorDlg()
41 // purpose : Constructs a BasicGUI_VectorDlg which is a child of 'parent', with the
42 // name 'name' and widget flags set to 'f'.
43 // The dialog will by default be modeless, unless you set 'modal' to
44 // TRUE to construct a modal dialog.
45 //=================================================================================
46 BasicGUI_VectorDlg::BasicGUI_VectorDlg(QWidget* parent, const char* name, BasicGUI* theBasicGUI, SALOME_Selection* Sel, bool modal, WFlags fl)
47 :GEOMBase_Skeleton(parent, name, Sel, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
49 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_VECTOR_2P")));
50 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_VECTOR_DXYZ")));
51 QPixmap image2(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_SELECT")));
53 setCaption(tr("GEOM_VECTOR_TITLE"));
55 /***************************************************************/
56 GroupConstructors->setTitle(tr("GEOM_VECTOR"));
57 RadioButton1->setPixmap(image0);
58 RadioButton2->setPixmap(image1);
59 RadioButton3->close(TRUE);
61 GroupPoints = new DlgRef_2Sel_QTD(this, "GroupPoints");
62 GroupPoints->GroupBox1->setTitle(tr("GEOM_POINTS"));
63 GroupPoints->TextLabel1->setText(tr("GEOM_POINT_I").arg("1"));
64 GroupPoints->TextLabel2->setText(tr("GEOM_POINT_I").arg("2"));
65 GroupPoints->PushButton1->setPixmap(image2);
66 GroupPoints->PushButton2->setPixmap(image2);
68 GroupDimensions = new DlgRef_3Spin1Check(this, "GroupDimensions");
69 GroupDimensions->GroupBox1->setTitle(tr("GEOM_COORDINATES"));
70 GroupDimensions->TextLabel1->setText(tr("GEOM_DX"));
71 GroupDimensions->TextLabel2->setText(tr("GEOM_DY"));
72 GroupDimensions->TextLabel3->setText(tr("GEOM_DZ"));
73 GroupDimensions->CheckBox1->setText(tr("GEOM_REVERSE_VECTOR"));
75 Layout1->addWidget(GroupPoints, 1, 0);
76 Layout1->addWidget(GroupDimensions, 1, 0);
77 /***************************************************************/
80 myBasicGUI = theBasicGUI;
85 //=================================================================================
86 // function : ~BasicGUI_VectorDlg()
87 // purpose : Destroys the object and frees any allocated resources
88 //=================================================================================
89 BasicGUI_VectorDlg::~BasicGUI_VectorDlg()
91 /* no need to delete child widgets, Qt does it all for us */
95 //=================================================================================
98 //=================================================================================
99 void BasicGUI_VectorDlg::Init()
103 myEditCurrentArgument = GroupPoints->LineEdit1;
108 myPoint1.SetCoord(0.0, 0.0, 0.0);
109 myPoint2.SetCoord(0.0, 0.0, 0.0);
110 myOkPoint1 = myOkPoint2 = false;
112 /* Vertices Filter for all arguments */
113 myVertexFilter = new GEOM_ShapeTypeFilter(TopAbs_VERTEX, myGeom);
114 mySelection->AddFilter(myVertexFilter);
116 /* Get setting of step value from file configuration */
117 QString St = QAD_CONFIG->getSetting("Geometry:SettingsGeomStep");
118 step = St.toDouble();
120 /* min, max, step and decimals for spin boxes */
121 GroupDimensions->SpinBox_DX->RangeStepAndValidator(-999.999, 999.999, step, 3);
122 GroupDimensions->SpinBox_DY->RangeStepAndValidator(-999.999, 999.999, step, 3);
123 GroupDimensions->SpinBox_DZ->RangeStepAndValidator(-999.999, 999.999, step, 3);
125 GroupDimensions->SpinBox_DX->SetValue(myDx);
126 GroupDimensions->SpinBox_DY->SetValue(myDy);
127 GroupDimensions->SpinBox_DZ->SetValue(myDz);
129 GroupDimensions->CheckBox1->setChecked(FALSE);
131 /* signals and slots connections */
132 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
133 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
134 connect(GroupConstructors, SIGNAL(clicked(int)), this, SLOT(ConstructorsClicked(int)));
136 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
137 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
139 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
140 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
142 connect(GroupDimensions->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
143 connect(GroupDimensions->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
144 connect(GroupDimensions->SpinBox_DZ, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
146 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DX, SLOT(SetStep(double)));
147 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DY, SLOT(SetStep(double)));
148 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DZ, SLOT(SetStep(double)));
150 connect(GroupDimensions->CheckBox1, SIGNAL(stateChanged(int)), this, SLOT(ReverseVector(int)));
152 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
154 /* displays Dialog */
155 GroupDimensions->hide();
163 //=================================================================================
164 // function : ConstructorsClicked()
165 // purpose : Radio button management
166 //=================================================================================
167 void BasicGUI_VectorDlg::ConstructorsClicked(int constructorId)
169 myConstructorId = constructorId;
170 mySelection->ClearFilters();
171 myGeomBase->EraseSimulationShape();
172 disconnect(mySelection, 0, this, 0);
173 myOkPoint1 = myOkPoint2 = false;
175 switch (constructorId)
179 GroupDimensions->hide();
183 myEditCurrentArgument = GroupPoints->LineEdit1;
184 GroupPoints->LineEdit1->setText("");
185 GroupPoints->LineEdit2->setText("");
187 /* filter for next selection */
188 mySelection->AddFilter(myVertexFilter);
189 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
196 GroupDimensions->show();
202 GroupDimensions->SpinBox_DX->SetValue(myDx);
203 GroupDimensions->SpinBox_DY->SetValue(myDy);
204 GroupDimensions->SpinBox_DZ->SetValue(myDz);
206 myPoint1.SetCoord(0.0, 0.0, 0.0) ;
207 myPoint2.SetCoord(myDx, myDy, myDz);
209 GroupDimensions->CheckBox1->setChecked(FALSE);
211 mySimulationTopoDs = BRepBuilderAPI_MakeEdge(myPoint1, myPoint2).Shape();
212 /* Add arrow in simulation */
213 bool noNeedToTest = AddArrowToSimulation(mySimulationTopoDs);
214 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
222 //=================================================================================
223 // function : ClickOnOk()
225 //=================================================================================
226 void BasicGUI_VectorDlg::ClickOnOk()
228 this->ClickOnApply();
234 //=================================================================================
235 // function : ClickOnApply()
237 //=================================================================================
238 void BasicGUI_VectorDlg::ClickOnApply()
240 QAD_Application::getDesktop()->putInfo(tr(""));
241 if (mySimulationTopoDs.IsNull())
243 myGeomBase->EraseSimulationShape();
244 mySimulationTopoDs.Nullify();
246 switch(myConstructorId)
250 if(myOkPoint1 && myOkPoint2)
251 myBasicGUI->MakeVectorAndDisplay(myPoint1, myPoint2);
256 /* Recup args and call method */
257 myDx = GroupDimensions->SpinBox_DX->GetValue();
258 myDy = GroupDimensions->SpinBox_DY->GetValue();
259 myDz = GroupDimensions->SpinBox_DZ->GetValue();
260 myPoint1.SetCoord(0.0, 0.0, 0.0);
261 myPoint2.SetCoord(myDx, myDy, myDz);
262 myBasicGUI->MakeVectorAndDisplay(myPoint1, myPoint2);
270 //=================================================================================
271 // function : SelectionIntoArgument()
272 // purpose : Called when selection as changed or other case
273 //=================================================================================
274 void BasicGUI_VectorDlg::SelectionIntoArgument()
276 myGeomBase->EraseSimulationShape();
277 myEditCurrentArgument->setText("");
278 QString aString = ""; /* name of selection */
280 int nbSel = myGeomBase->GetNameOfSelectedIObjects(mySelection, aString);
282 if (myEditCurrentArgument == GroupPoints->LineEdit1)
284 else if ( myEditCurrentArgument == GroupPoints->LineEdit2)
291 if(!myGeomBase->GetTopoFromSelection(mySelection, S))
294 if(myEditCurrentArgument == GroupPoints->LineEdit1 && myGeomBase->VertexToPoint(S, myPoint1)) {
295 myEditCurrentArgument->setText(aString);
298 else if(myEditCurrentArgument == GroupPoints->LineEdit2 && myGeomBase->VertexToPoint(S, myPoint2)) {
299 myEditCurrentArgument->setText(aString);
303 if(myOkPoint1 && myOkPoint2 && myPoint1.Distance(myPoint2) > Precision::Confusion()) {
304 mySimulationTopoDs = BRepBuilderAPI_MakeEdge(myPoint1, myPoint2).Shape();
305 /* Add arrow in simulation */
306 bool noNeedToTest = this->AddArrowToSimulation(mySimulationTopoDs);
307 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
313 //=================================================================================
314 // function : SetEditCurrentArgument()
316 //=================================================================================
317 void BasicGUI_VectorDlg::SetEditCurrentArgument()
319 if(myConstructorId != 0)
322 QPushButton* send = (QPushButton*)sender();
324 if(send == GroupPoints->PushButton1) {
325 GroupPoints->LineEdit1->setFocus();
326 myEditCurrentArgument = GroupPoints->LineEdit1;
328 else if(send == GroupPoints->PushButton2) {
329 GroupPoints->LineEdit2->setFocus();
330 myEditCurrentArgument = GroupPoints->LineEdit2;
332 mySelection->AddFilter(myVertexFilter);
333 this->SelectionIntoArgument();
339 //=================================================================================
340 // function : LineEditReturnPressed()
342 //=================================================================================
343 void BasicGUI_VectorDlg::LineEditReturnPressed()
345 QLineEdit* send = (QLineEdit*)sender();
346 if(send == GroupPoints->LineEdit1)
347 myEditCurrentArgument = GroupPoints->LineEdit1;
348 else if (send == GroupPoints->LineEdit2)
349 myEditCurrentArgument = GroupPoints->LineEdit2;
353 GEOMBase_Skeleton::LineEditReturnPressed();
358 //=================================================================================
359 // function : ActivateThisDialog()
361 //=================================================================================
362 void BasicGUI_VectorDlg::ActivateThisDialog()
364 GEOMBase_Skeleton::ActivateThisDialog();
365 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
366 if(myConstructorId == 0)
367 mySelection->AddFilter(myVertexFilter);
368 if(!mySimulationTopoDs.IsNull())
369 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
374 //=================================================================================
375 // function : enterEvent()
377 //=================================================================================
378 void BasicGUI_VectorDlg::enterEvent(QEvent* e)
380 if(GroupConstructors->isEnabled())
382 this->ActivateThisDialog();
387 //=================================================================================
388 // function : ValueChangedInSpinBox()
390 //=================================================================================
391 void BasicGUI_VectorDlg::ValueChangedInSpinBox(double newValue)
393 myGeomBase->EraseSimulationShape();
394 mySimulationTopoDs.Nullify();
395 QObject* send = (QObject*)sender();
397 if(send == GroupDimensions->SpinBox_DX)
399 else if (send == GroupDimensions->SpinBox_DY)
401 else if (send == GroupDimensions->SpinBox_DZ)
404 myPoint1.SetCoord(0.0, 0.0, 0.0);
405 myPoint2.SetCoord(myDx, myDy, myDz);
407 if(myPoint1.Distance(myPoint2) > Precision::Confusion()) { // mySimulationTopoDs
408 mySimulationTopoDs = BRepBuilderAPI_MakeEdge(myPoint1, myPoint2).Shape();
409 /* Create simulation vector with an arrow */
410 this->AddArrowToSimulation(mySimulationTopoDs);
411 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
417 //=================================================================================
418 // function : AddArrowToSimulation()
419 // purpose : An arrow (cone topology) is added to 'modifiedShape'
420 // : to simulate a vector or an 'oriented line' display. The result is in 'modifiedShape'.
421 // : If an arrow can't be added returns false and 'modifiedShape' isn't modified !
422 //=================================================================================
423 bool BasicGUI_VectorDlg::AddArrowToSimulation(TopoDS_Shape& modifiedShape)
426 /* Try to add a cone simulation shape to show direction of a linear edge */
427 if(myGeomBase->CreateArrowForLinearEdge(modifiedShape, arrow)) {
428 TopoDS_Compound Comp;
430 B.MakeCompound (Comp);
431 B.Add(Comp, modifiedShape);
433 modifiedShape = Comp;
440 //=================================================================================
441 // function : ReverseVector()
442 // purpose : 'state' not used here
443 //=================================================================================
444 void BasicGUI_VectorDlg::ReverseVector(int state)
446 myGeomBase->EraseSimulationShape();
447 mySimulationTopoDs.Nullify();
450 GroupDimensions->SpinBox_DX->SetValue(myDx);
452 GroupDimensions->SpinBox_DY->SetValue(myDy);
454 GroupDimensions->SpinBox_DZ->SetValue(myDz);
456 myPoint1.SetCoord(0.0, 0.0, 0.0);
457 myPoint2.SetCoord(myDx, myDy, myDz);
459 /* In the appropriate constructor */
460 if(myPoint1.Distance(myPoint2) > Precision::Confusion()) {
461 mySimulationTopoDs = BRepBuilderAPI_MakeEdge(myPoint1, myPoint2).Shape();
462 /* Add arrow in simulation */
463 bool noNeedToTest = this->AddArrowToSimulation(mySimulationTopoDs);
464 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);