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 buttonApply->setFocus();
241 QAD_Application::getDesktop()->putInfo(tr(""));
242 if (mySimulationTopoDs.IsNull())
244 myGeomBase->EraseSimulationShape();
245 mySimulationTopoDs.Nullify();
247 switch(myConstructorId)
251 if(myOkPoint1 && myOkPoint2)
252 myBasicGUI->MakeVectorAndDisplay(myPoint1, myPoint2);
257 /* Recup args and call method */
258 myDx = GroupDimensions->SpinBox_DX->GetValue();
259 myDy = GroupDimensions->SpinBox_DY->GetValue();
260 myDz = GroupDimensions->SpinBox_DZ->GetValue();
261 myPoint1.SetCoord(0.0, 0.0, 0.0);
262 myPoint2.SetCoord(myDx, myDy, myDz);
263 myBasicGUI->MakeVectorAndDisplay(myPoint1, myPoint2);
271 //=================================================================================
272 // function : SelectionIntoArgument()
273 // purpose : Called when selection as changed or other case
274 //=================================================================================
275 void BasicGUI_VectorDlg::SelectionIntoArgument()
277 myGeomBase->EraseSimulationShape();
278 myEditCurrentArgument->setText("");
279 QString aString = ""; /* name of selection */
281 int nbSel = myGeomBase->GetNameOfSelectedIObjects(mySelection, aString);
283 if (myEditCurrentArgument == GroupPoints->LineEdit1)
285 else if ( myEditCurrentArgument == GroupPoints->LineEdit2)
292 if(!myGeomBase->GetTopoFromSelection(mySelection, S))
295 if(myEditCurrentArgument == GroupPoints->LineEdit1 && myGeomBase->VertexToPoint(S, myPoint1)) {
296 myEditCurrentArgument->setText(aString);
299 else if(myEditCurrentArgument == GroupPoints->LineEdit2 && myGeomBase->VertexToPoint(S, myPoint2)) {
300 myEditCurrentArgument->setText(aString);
304 if(myOkPoint1 && myOkPoint2 && myPoint1.Distance(myPoint2) > Precision::Confusion()) {
305 mySimulationTopoDs = BRepBuilderAPI_MakeEdge(myPoint1, myPoint2).Shape();
306 /* Add arrow in simulation */
307 bool noNeedToTest = this->AddArrowToSimulation(mySimulationTopoDs);
308 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
314 //=================================================================================
315 // function : SetEditCurrentArgument()
317 //=================================================================================
318 void BasicGUI_VectorDlg::SetEditCurrentArgument()
320 if(myConstructorId != 0)
323 QPushButton* send = (QPushButton*)sender();
325 if(send == GroupPoints->PushButton1) {
326 GroupPoints->LineEdit1->setFocus();
327 myEditCurrentArgument = GroupPoints->LineEdit1;
329 else if(send == GroupPoints->PushButton2) {
330 GroupPoints->LineEdit2->setFocus();
331 myEditCurrentArgument = GroupPoints->LineEdit2;
333 mySelection->AddFilter(myVertexFilter);
334 this->SelectionIntoArgument();
340 //=================================================================================
341 // function : LineEditReturnPressed()
343 //=================================================================================
344 void BasicGUI_VectorDlg::LineEditReturnPressed()
346 QLineEdit* send = (QLineEdit*)sender();
347 if(send == GroupPoints->LineEdit1)
348 myEditCurrentArgument = GroupPoints->LineEdit1;
349 else if (send == GroupPoints->LineEdit2)
350 myEditCurrentArgument = GroupPoints->LineEdit2;
354 GEOMBase_Skeleton::LineEditReturnPressed();
359 //=================================================================================
360 // function : ActivateThisDialog()
362 //=================================================================================
363 void BasicGUI_VectorDlg::ActivateThisDialog()
365 GEOMBase_Skeleton::ActivateThisDialog();
366 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
367 if(myConstructorId == 0)
368 mySelection->AddFilter(myVertexFilter);
369 if(!mySimulationTopoDs.IsNull())
370 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
375 //=================================================================================
376 // function : enterEvent()
378 //=================================================================================
379 void BasicGUI_VectorDlg::enterEvent(QEvent* e)
381 if(GroupConstructors->isEnabled())
383 this->ActivateThisDialog();
388 //=================================================================================
389 // function : ValueChangedInSpinBox()
391 //=================================================================================
392 void BasicGUI_VectorDlg::ValueChangedInSpinBox(double newValue)
394 myGeomBase->EraseSimulationShape();
395 mySimulationTopoDs.Nullify();
396 QObject* send = (QObject*)sender();
398 if(send == GroupDimensions->SpinBox_DX)
400 else if (send == GroupDimensions->SpinBox_DY)
402 else if (send == GroupDimensions->SpinBox_DZ)
405 myPoint1.SetCoord(0.0, 0.0, 0.0);
406 myPoint2.SetCoord(myDx, myDy, myDz);
408 if(myPoint1.Distance(myPoint2) > Precision::Confusion()) { // mySimulationTopoDs
409 mySimulationTopoDs = BRepBuilderAPI_MakeEdge(myPoint1, myPoint2).Shape();
410 /* Create simulation vector with an arrow */
411 this->AddArrowToSimulation(mySimulationTopoDs);
412 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
418 //=================================================================================
419 // function : AddArrowToSimulation()
420 // purpose : An arrow (cone topology) is added to 'modifiedShape'
421 // : to simulate a vector or an 'oriented line' display. The result is in 'modifiedShape'.
422 // : If an arrow can't be added returns false and 'modifiedShape' isn't modified !
423 //=================================================================================
424 bool BasicGUI_VectorDlg::AddArrowToSimulation(TopoDS_Shape& modifiedShape)
427 /* Try to add a cone simulation shape to show direction of a linear edge */
428 if(myGeomBase->CreateArrowForLinearEdge(modifiedShape, arrow)) {
429 TopoDS_Compound Comp;
431 B.MakeCompound (Comp);
432 B.Add(Comp, modifiedShape);
434 modifiedShape = Comp;
441 //=================================================================================
442 // function : ReverseVector()
443 // purpose : 'state' not used here
444 //=================================================================================
445 void BasicGUI_VectorDlg::ReverseVector(int state)
447 myGeomBase->EraseSimulationShape();
448 mySimulationTopoDs.Nullify();
451 GroupDimensions->SpinBox_DX->SetValue(myDx);
453 GroupDimensions->SpinBox_DY->SetValue(myDy);
455 GroupDimensions->SpinBox_DZ->SetValue(myDz);
457 myPoint1.SetCoord(0.0, 0.0, 0.0);
458 myPoint2.SetCoord(myDx, myDy, myDz);
460 /* In the appropriate constructor */
461 if(myPoint1.Distance(myPoint2) > Precision::Confusion()) {
462 mySimulationTopoDs = BRepBuilderAPI_MakeEdge(myPoint1, myPoint2).Shape();
463 /* Add arrow in simulation */
464 bool noNeedToTest = this->AddArrowToSimulation(mySimulationTopoDs);
465 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);