1 // VISU VISUGUI : GUI for SMESH 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 : VisuGUI_CubeAxesDlg.cxx
25 // Author : Sergey LITONIN
28 #include "VisuGUI_CubeAxesDlg.h"
31 #include "VisuGUI_Tools.h"
32 #include "VisuGUI_FontWg.h"
34 #include "SVTK_ViewWindow.h"
35 #include "SVTK_CubeAxesActor2D.h"
39 #include <qpushbutton.h>
40 #include <qtabwidget.h>
41 #include <qcheckbox.h>
42 #include <qgroupbox.h>
43 #include <qlineedit.h>
45 #include <qobjectlist.h>
46 #include <qvalidator.h>
48 #include <vtkAxisActor2D.h>
49 #include <vtkTextProperty.h>
53 * Description : Tab of dialog
56 //=======================================================================
57 // name : VisuGUI_AxisWg::AxisWg
58 // Purpose : Constructor
59 //=======================================================================
60 VisuGUI_AxisWg::VisuGUI_AxisWg (QWidget* theParent)
63 QValueList< QLabel* > aLabels;
67 myNameGrp = new QGroupBox(3, Qt::Vertical, tr("AXIS_NAME"), this);
68 myIsNameVisible = new QCheckBox(tr("IS_VISIBLE"), myNameGrp);
70 QHBox* aHBox = new QHBox(myNameGrp);
72 QLabel* aLabel = new QLabel(tr("NAME"), aHBox);
73 myAxisName = new QLineEdit(aHBox);
74 aLabels.append(aLabel);
76 aHBox = new QHBox(myNameGrp);
78 aLabel = new QLabel(tr("FONT"), aHBox);
79 myNameFont = new VisuGUI_FontWg(aHBox);
80 aLabels.append(aLabel);
85 myLabelsGrp = new QGroupBox(4, Qt::Vertical, tr("LABELS"), this);
86 myIsLabelsVisible = new QCheckBox(tr("IS_VISIBLE"), myLabelsGrp);
88 aHBox = new QHBox(myLabelsGrp);
90 aLabel = new QLabel(tr("NUMBER"), aHBox);
91 myLabelNumber = new QLineEdit(aHBox);
92 myLabelNumber->setValidator(new QIntValidator(0, 25, this));
93 myLabelNumber->installEventFilter(this);
94 aLabels.append(aLabel);
96 aHBox = new QHBox(myLabelsGrp);
98 aLabel = new QLabel(tr("OFFSET"), aHBox);
99 myLabelOffset = new QLineEdit(aHBox);
100 aLabels.append(aLabel);
102 aHBox = new QHBox(myLabelsGrp);
103 aHBox->setSpacing(5);
104 aLabel = new QLabel(tr("FONT"), aHBox);
105 myLabelsFont = new VisuGUI_FontWg(aHBox);
106 aLabels.append(aLabel);
110 myTicksGrp = new QGroupBox(2, Qt::Vertical, tr("TICK_MARKS"), this);
111 myIsTicksVisible = new QCheckBox(tr("IS_VISIBLE"), myTicksGrp);
113 aHBox = new QHBox(myTicksGrp);
114 aHBox->setSpacing(5);
115 aLabel = new QLabel(tr("LENGTH"), aHBox);
116 myTickLength = new QLineEdit(aHBox);
117 aLabels.append(aLabel);
121 QVBoxLayout* aLay = new QVBoxLayout(this, 0, 5);
122 aLay->addWidget(myNameGrp);
123 aLay->addWidget(myLabelsGrp);
124 aLay->addWidget(myTicksGrp);
127 myIsNameVisible->setChecked(true);
128 myIsLabelsVisible->setChecked(true);
129 myIsTicksVisible->setChecked(true);
130 updateControlState();
132 // Adjust label widths
133 QValueList< QLabel* >::iterator anIter;
135 for (anIter = aLabels.begin(); anIter != aLabels.end(); anIter++)
136 aMaxWidth = QMAX(aMaxWidth, (*anIter)->sizeHint().width());
137 for (anIter = aLabels.begin(); anIter != aLabels.end(); anIter++)
138 (*anIter)->setFixedWidth(aMaxWidth);
140 // connect signals and slots
141 connect(myIsNameVisible, SIGNAL(stateChanged(int)), SLOT(onNameChecked()));
142 connect(myIsLabelsVisible, SIGNAL(stateChanged(int)), SLOT(onLabelsChecked()));
143 connect(myIsTicksVisible, SIGNAL(stateChanged(int)), SLOT(onTicksChecked()));
146 VisuGUI_AxisWg::~VisuGUI_AxisWg()
150 void VisuGUI_AxisWg::updateControlState()
157 bool VisuGUI_AxisWg::eventFilter(QObject* o, QEvent* e)
159 if (e->type() == QEvent::FocusOut) {
161 int k = myLabelNumber->text().toInt(&isOK);
162 if (isOK && k > 25) myLabelNumber->setText("25");
167 //=======================================================================
168 // name : VisuGUI_AxisWg::onNameChecked
170 //=======================================================================
171 void VisuGUI_AxisWg::setEnabled(QGroupBox* theGrp, const bool theState)
173 QObjectList aChildren(*theGrp->children());
175 for(anObj = aChildren.first(); anObj !=0; anObj = aChildren.next())
176 if (anObj !=0 && anObj->inherits("QHBox"))
177 ((QHBox*)anObj)->setEnabled(theState);
180 //=======================================================================
181 // Labels : VisuGUI_AxisWg::onLabelsChecked
183 //=======================================================================
184 void VisuGUI_AxisWg::onLabelsChecked()
186 setEnabled(myLabelsGrp, myIsLabelsVisible->isChecked());
189 //=======================================================================
190 // Labels : VisuGUI_AxisWg::onTicksChecked
192 //=======================================================================
193 void VisuGUI_AxisWg::onTicksChecked()
195 setEnabled(myTicksGrp, myIsTicksVisible->isChecked());
198 //=======================================================================
199 // name : VisuGUI_AxisWg::onNameChecked
201 //=======================================================================
202 void VisuGUI_AxisWg::onNameChecked()
204 setEnabled(myNameGrp, myIsNameVisible->isChecked());
207 //=======================================================================
208 // name : VisuGUI_AxisWg::UseName
210 //=======================================================================
211 void VisuGUI_AxisWg::UseName(const bool toUse)
213 myIsNameVisible->setChecked(toUse);
216 //=======================================================================
217 // name : VisuGUI_AxisWg::SetName
219 //================================================== =====================
220 void VisuGUI_AxisWg::SetName(const QString& theName)
222 myAxisName->setText(theName);
225 //=======================================================================
226 // name : VisuGUI_AxisWg::SetNameFont
228 //=======================================================================
229 void VisuGUI_AxisWg::SetNameFont(const QColor& theColor,
231 const bool theIsBold,
232 const bool theIsItalic,
233 const bool theIsShadow)
235 myNameFont->SetData(theColor, theFont, theIsBold, theIsItalic, theIsShadow);
238 //=======================================================================
239 // name : VisuGUI_AxisWg::SetNameFont
241 //=======================================================================
242 bool VisuGUI_AxisWg::ReadData(vtkAxisActor2D* theActor)
249 bool useName = theActor->GetTitleVisibility();
250 QString aTitle(theActor->GetTitle());
252 QColor aTitleColor(255, 255, 255);
253 int aTitleFontFamily = VTK_ARIAL;
254 bool isTitleBold = false;
255 bool isTitleItalic = false;
256 bool isTitleShadow = false;
258 vtkTextProperty* aTitleProp = theActor->GetTitleTextProperty();
262 aTitleProp->GetColor(c);
263 aTitleColor.setRgb((int)(c[ 0 ] * 255), (int)(c[ 1 ] * 255), (int)(c[ 2 ] * 255));
264 aTitleFontFamily = aTitleProp->GetFontFamily();
265 isTitleBold = aTitleProp->GetBold() ? true : false;
266 isTitleItalic = aTitleProp->GetItalic() ? true : false;
267 isTitleShadow = aTitleProp->GetShadow() ? true : false;
270 myIsNameVisible->setChecked(useName);
271 myAxisName->setText(aTitle);
272 myNameFont->SetData(aTitleColor, aTitleFontFamily, isTitleBold, isTitleItalic, isTitleShadow);
276 bool useLabels = theActor->GetLabelVisibility();
277 int nbLabels = theActor->GetNumberOfLabels();
278 int anOffset = theActor->GetTickOffset();
280 QColor aLabelsColor(255, 255, 255);
281 int aLabelsFontFamily = VTK_ARIAL;
282 bool isLabelsBold = false;
283 bool isLabelsItalic = false;
284 bool isLabelsShadow = false;
286 vtkTextProperty* aLabelsProp = theActor->GetLabelTextProperty();
290 aLabelsProp->GetColor(c);
291 aLabelsColor.setRgb((int)(c[ 0 ] * 255), (int)(c[ 1 ] * 255), (int)(c[ 2 ] * 255));
292 aLabelsFontFamily = aLabelsProp->GetFontFamily();
293 isLabelsBold = aLabelsProp->GetBold() ? true : false;
294 isLabelsItalic = aLabelsProp->GetItalic() ? true : false;
295 isLabelsShadow = aLabelsProp->GetShadow() ? true : false;
298 myIsLabelsVisible->setChecked(useLabels);
299 myLabelNumber->setText(QString("%1").arg(nbLabels));
300 myLabelOffset->setText(QString("%1").arg(anOffset));
301 myLabelsFont->SetData(aLabelsColor, aLabelsFontFamily, isLabelsBold, isLabelsItalic, isLabelsShadow);
304 bool useTickMarks = theActor->GetTickVisibility();
305 int aTickLength = theActor->GetTickLength();
307 myIsTicksVisible->setChecked(useTickMarks);
308 myTickLength->setText(QString("%1").arg(aTickLength));
313 //=======================================================================
314 // name : VisuGUI_CubeAxesDlg::Apply
316 //=======================================================================
317 bool VisuGUI_AxisWg::Apply(vtkAxisActor2D* theActor)
324 theActor->SetTitleVisibility(myIsNameVisible->isChecked() ? 1 : 0);
325 theActor->SetTitle(myAxisName->text().latin1());
327 QColor aTitleColor(255, 255, 255);
328 int aTitleFontFamily = VTK_ARIAL;
329 bool isTitleBold = false;
330 bool isTitleItalic = false;
331 bool isTitleShadow = false;
333 myNameFont->GetData(aTitleColor, aTitleFontFamily, isTitleBold, isTitleItalic, isTitleShadow);
334 vtkTextProperty* aTitleProp = theActor->GetTitleTextProperty();
337 aTitleProp->SetColor(aTitleColor.red() / 255.,
338 aTitleColor.green() / 255.,
339 aTitleColor.blue() / 255.);
340 aTitleProp->SetFontFamily(aTitleFontFamily);
342 aTitleProp->SetBold(isTitleBold ? 1 : 0);
343 aTitleProp->SetItalic(isTitleItalic ? 1 : 0);
344 aTitleProp->SetShadow(isTitleShadow ? 1 : 0);
346 theActor->SetTitleTextProperty(aTitleProp);
351 theActor->SetLabelVisibility(myIsLabelsVisible->isChecked() ? 1 : 0);
354 int nbLabels = myLabelNumber->text().toInt(&isOk);
356 theActor->SetNumberOfLabels(nbLabels);
358 int anOffset = myLabelOffset->text().toInt(&isOk);
360 theActor->SetTickOffset(anOffset);
362 QColor aLabelsColor(255, 255, 255);
363 int aLabelsFontFamily = VTK_ARIAL;
364 bool isLabelsBold = false;
365 bool isLabelsItalic = false;
366 bool isLabelsShadow = false;
368 myLabelsFont->GetData(aLabelsColor, aLabelsFontFamily, isLabelsBold, isLabelsItalic, isLabelsShadow);
369 vtkTextProperty* aLabelsProp = theActor->GetLabelTextProperty();
372 aLabelsProp->SetColor(aLabelsColor.red() / 255.,
373 aLabelsColor.green() / 255.,
374 aLabelsColor.blue() / 255.);
375 aLabelsProp->SetFontFamily(aLabelsFontFamily);
377 aLabelsProp->SetBold(isLabelsBold ? 1 : 0);
378 aLabelsProp->SetItalic(isLabelsItalic ? 1 : 0);
379 aLabelsProp->SetShadow(isLabelsShadow ? 1 : 0);
381 aLabelsProp->Modified();
382 theActor->SetLabelTextProperty(aLabelsProp);
387 theActor->SetTickVisibility(myIsTicksVisible->isChecked());
388 int aTickLength = myTickLength->text().toInt(&isOk);
390 theActor->SetTickLength(aTickLength);
396 Class : VisuGUI_CubeAxesDlg
397 Description : Dialog for specifynig cube axes properties
400 //=======================================================================
401 // name : VisuGUI_CubeAxesDlg::VisuGUI_CubeAxesDlg
402 // Purpose : Constructor
403 //=======================================================================
404 VisuGUI_CubeAxesDlg::VisuGUI_CubeAxesDlg(QWidget* theParent)
405 : QDialog(theParent, "VisuGUI_CubeAxesDlg", false,
406 WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | WDestructiveClose)
408 setCaption(tr("CAPTION"));
410 QVBoxLayout* aLay = new QVBoxLayout(this, 5, 5);
411 aLay->addWidget(createMainFrame(this));
412 aLay->addWidget(createButtonFrame(this));
416 //if (VISU::GetDesktop()->getMainFrame())
417 // connect(VISU::GetDesktop()->getMainFrame(), SIGNAL(windowActivated(QWidget*)),
418 // SLOT(onWindowActivated(QWidget*)));
421 //=======================================================================
422 // name : VisuGUI_CubeAxesDlg::createMainFrame
423 // Purpose : Create frame containing dialog's input fields
424 //=======================================================================
425 QWidget* VisuGUI_CubeAxesDlg::createMainFrame(QWidget* theParent)
427 QFrame* aFrame = new QFrame(theParent);
429 myTabWg = new QTabWidget(aFrame);
431 myAxes[ 0 ] = new VisuGUI_AxisWg(myTabWg);
432 myAxes[ 1 ] = new VisuGUI_AxisWg(myTabWg);
433 myAxes[ 2 ] = new VisuGUI_AxisWg(myTabWg);
435 myTabWg->addTab(myAxes[ 0 ], tr("X_AXIS"));
436 myTabWg->addTab(myAxes[ 1 ], tr("Y_AXIS"));
437 myTabWg->addTab(myAxes[ 2 ], tr("Z_AXIS"));
439 myTabWg->setMargin(5);
441 myIsVisible = new QCheckBox(tr("IS_VISIBLE"), aFrame);
443 QVBoxLayout* aLay = new QVBoxLayout(aFrame, 0, 5);
444 aLay->addWidget(myTabWg);
445 aLay->addWidget(myIsVisible);
450 //=======================================================================
451 // name : VisuGUI_CubeAxesDlg::createButtonFrame
452 // Purpose : Create frame containing buttons
453 //=======================================================================
454 QWidget* VisuGUI_CubeAxesDlg::createButtonFrame(QWidget* theParent)
456 QFrame* aFrame = new QFrame(theParent);
457 aFrame->setFrameStyle(QFrame::Box | QFrame::Sunken);
459 myOkBtn = new QPushButton(tr("BUT_OK"), aFrame);
460 myApplyBtn = new QPushButton(tr("BUT_APPLY"), aFrame);
461 myCloseBtn = new QPushButton(tr("BUT_CLOSE"), aFrame);
463 QSpacerItem* aSpacer = new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum);
465 QHBoxLayout* aLay = new QHBoxLayout(aFrame, 5, 5);
467 aLay->addWidget(myOkBtn);
468 aLay->addWidget(myApplyBtn);
469 aLay->addItem(aSpacer);
470 aLay->addWidget(myCloseBtn);
472 connect(myOkBtn, SIGNAL(clicked()), SLOT(onOk()));
473 connect(myApplyBtn, SIGNAL(clicked()), SLOT(onApply()));
474 connect(myCloseBtn, SIGNAL(clicked()), SLOT(onClose()));
479 //=======================================================================
480 // name : VisuGUI_CubeAxesDlg::~VisuGUI_CubeAxesDlg
481 // Purpose : Destructor
482 //=======================================================================
483 VisuGUI_CubeAxesDlg::~VisuGUI_CubeAxesDlg()
487 //=======================================================================
488 // name : VisuGUI_CubeAxesDlg::Init
489 // Purpose : Init dialog fields, connect signals and slots, show dialog
490 //=======================================================================
491 bool VisuGUI_CubeAxesDlg::Init()
493 SVTK_ViewWindow* aFrame = VISU::GetViewWindow();
497 SVTK_CubeAxesActor2D* anActor = aFrame->GetCubeAxes();
501 myAxes[ 0 ]->ReadData(anActor->GetXAxisActor2D());
502 myAxes[ 1 ]->ReadData(anActor->GetYAxisActor2D());
503 myAxes[ 2 ]->ReadData(anActor->GetZAxisActor2D());
505 myIsVisible->setChecked(anActor->GetVisibility() ? true : false);
511 //=======================================================================
512 // name : VisuGUI_CubeAxesDlg::isValid
513 // Purpose : Verify validity of entry data
514 //=======================================================================
515 bool VisuGUI_CubeAxesDlg::isValid() const
520 //=======================================================================
521 // name : VisuGUI_CubeAxesDlg::onApply
522 // Purpose : Verify validity of entry data
523 //=======================================================================
524 bool VisuGUI_CubeAxesDlg::onApply()
530 SVTK_ViewWindow* aFrame = VISU::GetViewWindow();
534 SVTK_CubeAxesActor2D* anActor = aFrame->GetCubeAxes();
538 isOk = isOk && myAxes[ 0 ]->Apply(anActor->GetXAxisActor2D());
539 isOk = isOk && myAxes[ 1 ]->Apply(anActor->GetYAxisActor2D());
540 isOk = isOk && myAxes[ 2 ]->Apply(anActor->GetZAxisActor2D());
543 //anActor->SetXLabel(myAxes[ 0 ]->myAxisName->text());
544 //anActor->SetYLabel(myAxes[ 1 ]->myAxisName->text());
545 //anActor->SetZLabel(myAxes[ 2 ]->myAxisName->text());
547 //anActor->SetNumberOfLabels(anActor->GetXAxisActor2D()->GetNumberOfLabels());
548 if (myIsVisible->isChecked())
549 anActor->VisibilityOn();
551 anActor->VisibilityOff();
564 //=======================================================================
565 // name : VisuGUI_CubeAxesDlg::onOk
566 // Purpose : SLOT called when "Ok" button pressed.
567 //=======================================================================
568 void VisuGUI_CubeAxesDlg::onOk()
574 //=======================================================================
575 // name : VisuGUI_CubeAxesDlg::onClose
576 // Purpose : SLOT called when "Close" button pressed. Close dialog
577 //=======================================================================
578 void VisuGUI_CubeAxesDlg::onClose()
583 //=======================================================================
584 // name : VisuGUI_CubeAxesDlg::onClose
585 // Purpose : SLOT called when "Close" button pressed. Close dialog
586 //=======================================================================
587 void VisuGUI_CubeAxesDlg::onWindowActivated (QWidget*)
589 SVTK_ViewWindow* aFrame = VISU::GetViewWindow();