geom/src/EntityGUI/EntityGUI_3DSketcherDlg.cxx

1499 lines
53 KiB
C++
Raw Normal View History

2012-08-09 13:58:02 +06:00
// Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE
2009-02-13 17:16:39 +05:00
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
2012-08-09 13:58:02 +06:00
// GEOM GEOMGUI : GUI for Geometry component
2009-02-13 17:16:39 +05:00
// File : EntityGUI_3DSketcherDlg.cxx
// Author : DMV, OCN
2012-10-08 17:16:36 +06:00
2012-08-09 13:58:02 +06:00
#include <cmath>
#include <string>
#include <boost/lexical_cast.hpp>
2009-02-13 17:16:39 +05:00
#include "EntityGUI_3DSketcherDlg.h"
#include "EntityGUI_Widgets.h"
2012-08-09 13:58:02 +06:00
#include <SalomeApp_DoubleSpinBox.h>
2009-02-13 17:16:39 +05:00
#include <GEOMBase.h>
#include <GeometryGUI.h>
2012-10-08 17:16:36 +06:00
#include <Precision.hxx>
2009-02-13 17:16:39 +05:00
#include <DlgRef.h>
#include <SUIT_Session.h>
2012-08-09 13:58:02 +06:00
#include <SUIT_Desktop.h>
2009-02-13 17:16:39 +05:00
#include <SUIT_MessageBox.h>
#include <SUIT_ResourceMgr.h>
2012-08-09 13:58:02 +06:00
#include <SUIT_ViewWindow.h>
#include <SUIT_ViewManager.h>
#include <SOCC_Prs.h>
#include <SOCC_ViewModel.h>
2009-02-13 17:16:39 +05:00
#include <SalomeApp_Application.h>
#include <LightApp_Application.h>
#include <LightApp_SelectionMgr.h>
2012-08-09 13:58:02 +06:00
#include <SalomeApp_Tools.h>
//OCCT includes
2009-02-13 17:16:39 +05:00
#include <TopoDS.hxx>
#include <TColStd_IndexedMapOfInteger.hxx>
2012-08-09 13:58:02 +06:00
#include <BRepBuilderAPI_MakeVertex.hxx>
#include <BRepBuilderAPI_MakePolygon.hxx>
#include <BRepBuilderAPI_MakeEdge.hxx>
#include <AIS_Trihedron.hxx>
#include <AIS_AngleDimension.hxx>
#include <AIS_LengthDimension.hxx>
#include <AIS_Drawer.hxx>
#include <Geom_Axis2Placement.hxx>
#include <Geom_Plane.hxx>
#include <SelectMgr_Selection.hxx>
#include <gce_MakePln.hxx>
#include <Prs3d_AngleAspect.hxx>
#include <Prs3d_LineAspect.hxx>
#include <Prs3d_LengthAspect.hxx>
// This include must be *AFTER* SOCC_ViewModel.h because
// of the constant ROTATE which is a #define in
// GEOMImpl_Types.hxx and an enum in SOCC_ViewModel.h
#include <GEOMImpl_Types.hxx>
enum
{
NONE,
TYPE_LENGTH,
TYPE_ANGLE,
TYPE_TWO_ANGLES
};
2009-02-13 17:16:39 +05:00
2012-10-08 17:16:36 +06:00
enum
{
OXY,
OYZ,
OXZ
};
2009-02-13 17:16:39 +05:00
class Locker
{
public:
2012-10-08 17:16:36 +06:00
Locker(bool& l) : myLock(l) { myLock = true; }
~Locker() { myLock = false; }
2009-02-13 17:16:39 +05:00
private:
bool& myLock;
};
//=================================================================================
// class : EntityGUI_3DSketcherDlg()
// purpose : Constructs a EntityGUI_3DSketcherDlg which is a child of 'parent', with the
// name 'name' and widget flags set to 'f'.
// The dialog will by default be modeless, unless you set 'modal' to
// TRUE to construct a modal dialog.
//=================================================================================
2012-10-08 17:16:36 +06:00
EntityGUI_3DSketcherDlg::EntityGUI_3DSketcherDlg (GeometryGUI* theGeometryGUI, QWidget* parent,
2012-08-09 13:58:02 +06:00
bool modal, Qt::WindowFlags fl,
2012-10-08 17:16:36 +06:00
const double lineWidth)
: GEOMBase_Skeleton(theGeometryGUI, parent, modal, fl),
myMode(-1),
myOK(false),
myLineWidth(lineWidth),
myGeometryGUI(theGeometryGUI),
2012-08-09 13:58:02 +06:00
myLengthIORedoList()
2012-10-08 17:16:36 +06:00
// myLastAngleNormal()
2009-02-13 17:16:39 +05:00
{
2012-10-08 17:16:36 +06:00
QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_SELECT")));
QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_UNDO")));
QPixmap image2(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_REDO")));
QPixmap image3(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICO_3DSKETCH")));
2009-02-13 17:16:39 +05:00
2012-10-08 17:16:36 +06:00
setWindowTitle(tr("GEOM_3DSKETCHER_TITLE"));
2009-02-13 17:16:39 +05:00
/***************************************************************/
2012-10-08 17:16:36 +06:00
mainFrame()->GroupConstructors->setTitle(tr("GEOM_3DSKETCHER"));
mainFrame()->RadioButton1->setIcon(image3);;
2009-02-13 17:16:39 +05:00
mainFrame()->RadioButton2->close();
mainFrame()->RadioButton3->close();
GroupType = new DlgRef_3Radio(centralWidget());
GroupType->GroupBox1->setTitle(tr("GEOM_COORDINATES_TYPE"));
GroupType->RadioButton1->setText(tr("GEOM_SKETCHER_ABS"));
GroupType->RadioButton2->setText(tr("GEOM_SKETCHER_REL"));
2012-08-09 13:58:02 +06:00
GroupType->RadioButton3->setText(tr("Angles")); //TODO translation
// GroupType->RadioButton3->close();
2012-10-08 17:16:36 +06:00
myTypeGroup = new QButtonGroup(this);
myTypeGroup->addButton(GroupType->RadioButton1, 0);
myTypeGroup->addButton(GroupType->RadioButton2, 1);
myTypeGroup->addButton(GroupType->RadioButton3, 2);
Group3Spin = new EntityGUI_3Spin(centralWidget());
Group3Spin->GroupBox1->setTitle(tr("GEOM_SKETCHER_VALUES"));
Group3Spin->buttonApply->setText(tr("GEOM_SKETCHER_APPLY"));
Group3Spin->buttonUndo->setIcon(image1);
Group3Spin->buttonRedo->setIcon(image2);
Group3Spin->TextLabel1->setText(tr("GEOM_SKETCHER_X2"));
Group3Spin->TextLabel2->setText(tr("GEOM_SKETCHER_Y2"));
Group3Spin->TextLabel3->setText(tr("GEOM_SKETCHER_Z2"));
GroupAngles = new EntityGUI_Angles(centralWidget());
GroupAngles->buttonApply->setText(tr("GEOM_SKETCHER_APPLY"));
GroupAngles->buttonUndo->setIcon(image1);
GroupAngles->buttonRedo->setIcon(image2);
GroupAngles->checkBox->setText(tr("Angle 2")); //TODO translation
GroupControls = new EntityGUI_Controls(centralWidget());
2012-08-09 13:58:02 +06:00
GroupControls->GroupBox1->setTitle(tr("GEOM_CONTROLS"));
2012-10-08 17:16:36 +06:00
GroupControls->CheckBox1->setText(tr("Show length dimensions")); //TODO translation
GroupControls->CheckBox2->setText(tr("Show angle dimensions")); //TODO translation
GroupControls->CheckBox3->setText(tr("Show start/end point coordinates")); //TODO translation
GroupControls->lineEdit_1->setReadOnly(true);
GroupControls->lineEdit_2->setReadOnly(true);
GroupControls->lineEdit_3->setReadOnly(true);
GroupControls->lineEdit_4->setReadOnly(true);
GroupControls->lineEdit_5->setReadOnly(true);
GroupControls->lineEdit_6->setReadOnly(true);
GroupControls->label_1->setText(tr("X:"));
GroupControls->label_2->setText(tr("Y:"));
GroupControls->label_3->setText(tr("Z:"));
GroupControls->label_4->setText(tr("X:"));
GroupControls->label_5->setText(tr("Y:"));
GroupControls->label_6->setText(tr("Z:"));
buttonOk()->setText(tr("GEOM_BUT_END_SKETCH"));
buttonApply()->setText(tr("GEOM_BUT_CLOSE_SKETCH"));
QVBoxLayout* layout = new QVBoxLayout(centralWidget());
layout->setMargin(0); layout->setSpacing(6);
layout->addWidget(GroupType);
layout->addWidget(Group3Spin);
layout->addWidget(GroupAngles);
layout->addWidget(GroupControls);
setHelpFileName("create_3dsketcher_page.html");
2009-02-13 17:16:39 +05:00
2012-08-09 13:58:02 +06:00
resize(100,100);
2009-02-13 17:16:39 +05:00
Init();
2012-10-08 17:16:36 +06:00
}
2009-02-13 17:16:39 +05:00
//=================================================================================
// function : ~EntityGUI_3DSketcherDlg()
// purpose : Destroys the object and frees any allocated resources
//=================================================================================
EntityGUI_3DSketcherDlg::~EntityGUI_3DSketcherDlg()
{
2012-10-08 17:16:36 +06:00
myGeomGUI->SetActiveDialogBox(0);
2009-02-13 17:16:39 +05:00
}
//=================================================================================
// function : Init()
// purpose :
//=================================================================================
void EntityGUI_3DSketcherDlg::Init()
{
myOK = false;
2012-10-08 17:16:36 +06:00
myOrientation = OXY;
2012-08-09 13:58:02 +06:00
myPrsType = NONE;
2012-10-08 17:16:36 +06:00
2012-08-09 13:58:02 +06:00
SUIT_ViewWindow* vw = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
myAnglePrs = dynamic_cast<SOCC_Prs*>(((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->CreatePrs(0));
myLengthPrs = dynamic_cast<SOCC_Prs*>(((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->CreatePrs(0));
2012-10-08 17:16:36 +06:00
2012-08-09 13:58:02 +06:00
//TEST
2012-10-08 17:16:36 +06:00
localSelection(GEOM::GEOM_Object::_nil(), TopAbs_VERTEX);
2012-08-09 13:58:02 +06:00
// globalSelection(GEOM_PREVIEW);
2012-10-08 17:16:36 +06:00
// setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
2009-02-13 17:16:39 +05:00
/* Get setting of step value from file configuration */
2012-10-08 17:16:36 +06:00
double step = SUIT_Session::session()->resourceMgr()->doubleValue("Geometry", "SettingsGeomStep", 100.0);
2009-02-13 17:16:39 +05:00
/* min, max, step and decimals for spin boxes */
2012-10-08 17:16:36 +06:00
initSpinBox(Group3Spin->SpinBox_DX, COORD_MIN, COORD_MAX, step, "length_precision");
initSpinBox(Group3Spin->SpinBox_DY, COORD_MIN, COORD_MAX, step, "length_precision");
initSpinBox(Group3Spin->SpinBox_DZ, COORD_MIN, COORD_MAX, step, "length_precision");
initSpinBox(GroupAngles->SpinBox_DA , -180.0, 180.0, step, "angular_precision");
initSpinBox(GroupAngles->SpinBox_DA2, -90.0, 90.0, step, "angular_precision");
initSpinBox(GroupAngles->SpinBox_DL , COORD_MIN, COORD_MAX, step, "length_precision");
2009-02-13 17:16:39 +05:00
2012-08-09 13:58:02 +06:00
Group3Spin->SpinBox_DX->setValue(0.0);
Group3Spin->SpinBox_DY->setValue(0.0);
Group3Spin->SpinBox_DZ->setValue(0.0);
2012-10-08 17:16:36 +06:00
2012-08-09 13:58:02 +06:00
GroupAngles->SpinBox_DA->setValue(0.0);
GroupAngles->SpinBox_DA2->setValue(0.0);
GroupAngles->SpinBox_DL->setValue(0.0);
2012-10-08 17:16:36 +06:00
2012-08-09 13:58:02 +06:00
GroupAngles->radioButton_1->setChecked(true);
GroupAngles->checkBox->setChecked(false);
2012-10-08 17:16:36 +06:00
GroupAngles->SpinBox_DA2->setEnabled(false);
GroupControls->CheckBox1->setChecked(true);
GroupControls->CheckBox2->setChecked(true);
GroupControls->CheckBox3->setChecked(true);
2012-08-09 13:58:02 +06:00
isLengthVisible = true;
isAngleVisible = true;
2012-10-08 17:16:36 +06:00
2012-08-09 13:58:02 +06:00
GroupAngles->hide();
2009-02-13 17:16:39 +05:00
2012-08-09 13:58:02 +06:00
/* signals and slots connections */
2012-10-08 17:16:36 +06:00
connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk()));
connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
2009-02-13 17:16:39 +05:00
2012-10-08 17:16:36 +06:00
connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
2009-02-13 17:16:39 +05:00
2012-10-08 17:16:36 +06:00
connect(Group3Spin->buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnAddPoint()));
connect(Group3Spin->buttonUndo, SIGNAL(clicked()), this, SLOT(ClickOnUndo()));
connect(Group3Spin->buttonRedo, SIGNAL(clicked()), this, SLOT(ClickOnRedo())) ;
2009-02-13 17:16:39 +05:00
2012-10-08 17:16:36 +06:00
connect(GroupAngles->buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnAddPoint()));
connect(GroupAngles->buttonUndo, SIGNAL(clicked()), this, SLOT(ClickOnUndo()));
connect(GroupAngles->buttonRedo, SIGNAL(clicked()), this, SLOT(ClickOnRedo())) ;
2009-02-13 17:16:39 +05:00
2012-10-08 17:16:36 +06:00
connect(myTypeGroup, SIGNAL(buttonClicked(int)), this, SLOT(TypeClicked(int)));
connect(Group3Spin->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
connect(Group3Spin->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
connect(Group3Spin->SpinBox_DZ, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
connect(GroupAngles->SpinBox_DA, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
connect(GroupAngles->SpinBox_DA2, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
connect(GroupAngles->SpinBox_DL, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
connect(GroupAngles->radioButton_1, SIGNAL(clicked (bool)), this, SLOT(ButtonClicked(bool))) ;
connect(GroupAngles->radioButton_2, SIGNAL(clicked (bool)), this, SLOT(ButtonClicked(bool))) ;
connect(GroupAngles->radioButton_3, SIGNAL(clicked (bool)), this, SLOT(ButtonClicked(bool))) ;
connect(GroupAngles->checkBox, SIGNAL(clicked (bool)), this, SLOT(BoxChecked (bool))) ;
connect(GroupControls->CheckBox1, SIGNAL(clicked (bool)), this, SLOT(BoxChecked (bool))) ;
connect(GroupControls->CheckBox2, SIGNAL(clicked (bool)), this, SLOT(BoxChecked (bool))) ;
connect(GroupControls->CheckBox3, SIGNAL(clicked (bool)), this, SLOT(BoxChecked (bool))) ;
2009-02-13 17:16:39 +05:00
2012-10-08 17:16:36 +06:00
connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), this, SLOT(SetDoubleSpinBoxStep(double)));
2009-02-13 17:16:39 +05:00
2012-10-08 17:16:36 +06:00
connect(myGeomGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
connect(myGeomGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
2009-02-13 17:16:39 +05:00
2012-10-08 17:16:36 +06:00
initName(tr("GEOM_3DSKETCHER"));
GroupControls->CheckBox3->click();
2009-02-13 17:16:39 +05:00
UpdateButtonsState();
2012-10-08 17:16:36 +06:00
GEOMBase_Helper::displayPreview(true, false, true, true, myLineWidth);
2009-02-13 17:16:39 +05:00
}
//=================================================================================
// function : TypeClicked()
// purpose : Radio button management
//=================================================================================
2012-10-08 17:16:36 +06:00
void EntityGUI_3DSketcherDlg::TypeClicked (int mode)
2009-02-13 17:16:39 +05:00
{
2012-10-08 17:16:36 +06:00
if (mode == myMode) return;
2012-08-09 13:58:02 +06:00
GroupAngles->hide();
Group3Spin->show();
2012-10-08 17:16:36 +06:00
2009-02-13 17:16:39 +05:00
bool blocked = Group3Spin->SpinBox_DX->signalsBlocked();
Group3Spin->SpinBox_DX->blockSignals(true);
Group3Spin->SpinBox_DY->blockSignals(true);
Group3Spin->SpinBox_DZ->blockSignals(true);
2012-10-08 17:16:36 +06:00
2009-02-13 17:16:39 +05:00
// Get setting of step value from file configuration
2012-08-09 13:58:02 +06:00
XYZ xyz = getLastPoint();
bool okx, oky, okz;
2012-10-08 17:16:36 +06:00
Group3Spin->SpinBox_DX->text().toDouble(&okx);
Group3Spin->SpinBox_DY->text().toDouble(&oky);
Group3Spin->SpinBox_DZ->text().toDouble(&okz);
if (mode == 0) { // XYZ
Group3Spin->TextLabel1->setText(tr("GEOM_SKETCHER_X2"));
Group3Spin->TextLabel2->setText(tr("GEOM_SKETCHER_Y2"));
Group3Spin->TextLabel3->setText(tr("GEOM_SKETCHER_Z2"));
2012-08-09 13:58:02 +06:00
if (myMode == 1)
{
2012-10-08 17:16:36 +06:00
if (okx) Group3Spin->SpinBox_DX->setValue(xyz.x + Group3Spin->SpinBox_DX->value());
if (oky) Group3Spin->SpinBox_DY->setValue(xyz.y + Group3Spin->SpinBox_DY->value());
if (okz) Group3Spin->SpinBox_DZ->setValue(xyz.z + Group3Spin->SpinBox_DZ->value());
2012-08-09 13:58:02 +06:00
}
2009-02-13 17:16:39 +05:00
Group3Spin->buttonApply->setFocus();
2012-08-09 13:58:02 +06:00
}
2012-10-08 17:16:36 +06:00
else if (mode == 1) { // DXDYDZ
Group3Spin->TextLabel1->setText(tr("GEOM_SKETCHER_DX2"));
Group3Spin->TextLabel2->setText(tr("GEOM_SKETCHER_DY2"));
Group3Spin->TextLabel3->setText(tr("GEOM_SKETCHER_DZ2"));
2012-08-09 13:58:02 +06:00
if (myMode == 0)
{
2012-10-08 17:16:36 +06:00
if (okx) Group3Spin->SpinBox_DX->setValue(Group3Spin->SpinBox_DX->value() - xyz.x);
if (oky) Group3Spin->SpinBox_DY->setValue(Group3Spin->SpinBox_DY->value() - xyz.y);
if (okz) Group3Spin->SpinBox_DZ->setValue(Group3Spin->SpinBox_DZ->value() - xyz.z);
2012-08-09 13:58:02 +06:00
}
2009-02-13 17:16:39 +05:00
Group3Spin->buttonApply->setFocus();
}
2012-10-08 17:16:36 +06:00
else if (mode == 2) { // Angles and Length
2012-08-09 13:58:02 +06:00
Group3Spin->hide();
GroupAngles->show();
GroupAngles->buttonApply->setFocus();
}
2012-10-08 17:16:36 +06:00
2009-02-13 17:16:39 +05:00
Group3Spin->SpinBox_DX->blockSignals(blocked);
Group3Spin->SpinBox_DY->blockSignals(blocked);
Group3Spin->SpinBox_DZ->blockSignals(blocked);
2012-08-09 13:58:02 +06:00
myMode = mode;
2012-10-08 17:16:36 +06:00
2012-08-09 13:58:02 +06:00
updateGeometry();
resize(minimumSizeHint());
2012-10-08 17:16:36 +06:00
GEOMBase_Helper::displayPreview(true, false, true, true, myLineWidth);
2009-02-13 17:16:39 +05:00
}
//=================================================================================
// function : ClickOnAddPoint()
// purpose : called when the point coordinates is Applyed
//=================================================================================
void EntityGUI_3DSketcherDlg::ClickOnAddPoint()
2012-10-08 17:16:36 +06:00
{
2012-08-09 13:58:02 +06:00
QString msg;
2012-10-08 17:16:36 +06:00
if (!isValid(msg)) {
showError(msg);
2012-08-09 13:58:02 +06:00
return;
}
2012-10-08 17:16:36 +06:00
2012-08-09 13:58:02 +06:00
// Display and store angle dimensions interactive objects in Prs
2012-10-08 17:16:36 +06:00
if (GroupType->RadioButton3->isChecked()) // ANGLES
2012-08-09 13:58:02 +06:00
{
double anAngle2 = 0.0;
if (GroupAngles->checkBox->isChecked())
anAngle2 = GroupAngles->SpinBox_DA2->value();
2012-10-08 17:16:36 +06:00
2012-08-09 13:58:02 +06:00
// Store angle dimensions
2012-10-08 17:16:36 +06:00
displayAngle(GroupAngles->SpinBox_DA->value(), anAngle2,
GroupAngles->SpinBox_DL->value(), myOrientation, /*store =*/true);
// Store length dimensions
displayLength(GroupAngles->SpinBox_DL->value(), /*store =*/true, /*type=*/myPrsType);
2012-08-09 13:58:02 +06:00
}
2012-10-08 17:16:36 +06:00
2012-08-09 13:58:02 +06:00
// Display and store store length dimension interactive object in Prs
2012-10-08 17:16:36 +06:00
if (GroupType->RadioButton1->isChecked() || // ABSOLUTE or RELATIVE coordinates
2012-08-09 13:58:02 +06:00
GroupType->RadioButton2->isChecked())
{
displayLength(-1, /*store=*/true);
}
2012-10-08 17:16:36 +06:00
myPointsList.append(getCurrentPoint());
myPrsTypeList.push_back(myPrsType);
2012-08-09 13:58:02 +06:00
// Clean redo lists
2009-02-13 17:16:39 +05:00
myRedoList.clear();
2012-08-09 13:58:02 +06:00
myPrsTypeRedoList.clear();
myLengthIORedoList.Clear();
myAngleIORedoList.Clear();
2012-10-08 17:16:36 +06:00
if (myMode == 1)
{
Group3Spin->SpinBox_DX->setValue(0.0);
Group3Spin->SpinBox_DY->setValue(0.0);
Group3Spin->SpinBox_DZ->setValue(0.0);
2009-02-13 17:16:39 +05:00
}
2012-10-08 17:16:36 +06:00
else if (myMode == 2)
2012-08-09 13:58:02 +06:00
{
2012-10-08 17:16:36 +06:00
GroupAngles->SpinBox_DA->setValue(0.0);
GroupAngles->SpinBox_DL->setValue(0.0);
GroupAngles->SpinBox_DA2->setValue(0.0);
2012-08-09 13:58:02 +06:00
}
2012-10-08 17:16:36 +06:00
UpdatePointCoordinates();
UpdateButtonsState();
GEOMBase_Helper::displayPreview(true, false, true, true, myLineWidth);
2009-02-13 17:16:39 +05:00
}
//=================================================================================
// function : UpdateButtonsState()
2012-10-08 17:16:36 +06:00
// purpose :
2009-02-13 17:16:39 +05:00
//=================================================================================
void EntityGUI_3DSketcherDlg::UpdateButtonsState()
{
2012-10-08 17:16:36 +06:00
if (myPointsList.count() == 0) GroupType->RadioButton1->click();
GroupType->RadioButton2->setEnabled(myPointsList.count() > 0);
GroupType->RadioButton3->setEnabled(myPointsList.count() > 0);
Group3Spin->buttonUndo->setEnabled(myPointsList.count() > 0);
Group3Spin->buttonRedo->setEnabled(myRedoList.count() > 0);
GroupAngles->buttonUndo->setEnabled(myPointsList.count() > 0);
GroupAngles->buttonRedo->setEnabled(myRedoList.count() > 0);
}
//=================================================================================
// function : UpdatePointCoordinates()
// purpose :Update point coordinates in the control groupbox
//=================================================================================
void EntityGUI_3DSketcherDlg::UpdatePointCoordinates()
{
SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
int aPrecision = resMgr->integerValue("Geometry", "length_precision", 6);
if (myPointsList.count() == 0)
{
GroupControls->lineEdit_1->setText("");
GroupControls->lineEdit_2->setText("");
GroupControls->lineEdit_3->setText("");
GroupControls->lineEdit_4->setText("");
GroupControls->lineEdit_5->setText("");
GroupControls->lineEdit_6->setText("");
}
else if (myPointsList.count() == 1)
{
GroupControls->lineEdit_1->setText(DlgRef::PrintDoubleValue(getLastPoint().x, aPrecision));
GroupControls->lineEdit_2->setText(DlgRef::PrintDoubleValue(getLastPoint().y, aPrecision));
GroupControls->lineEdit_3->setText(DlgRef::PrintDoubleValue(getLastPoint().z, aPrecision));
GroupControls->lineEdit_4->setText("");
GroupControls->lineEdit_5->setText("");
GroupControls->lineEdit_6->setText("");
}
else
{
GroupControls->lineEdit_4->setText(DlgRef::PrintDoubleValue(getLastPoint().x, aPrecision));
GroupControls->lineEdit_5->setText(DlgRef::PrintDoubleValue(getLastPoint().y, aPrecision));
GroupControls->lineEdit_6->setText(DlgRef::PrintDoubleValue(getLastPoint().z, aPrecision));
}
2009-02-13 17:16:39 +05:00
}
//=================================================================================
// function : ClickOnUndo()
// purpose :
//=================================================================================
void EntityGUI_3DSketcherDlg::ClickOnUndo()
{
2012-08-09 13:58:02 +06:00
if (myPointsList.count() > 0) {
2012-10-08 17:16:36 +06:00
myRedoList.append(myPointsList.takeLast());
2009-02-13 17:16:39 +05:00
UpdateButtonsState();
2012-10-08 17:16:36 +06:00
GEOMBase_Helper::displayPreview(true, false, true, true, myLineWidth);
2012-08-09 13:58:02 +06:00
// Erase dimensions presentations
SUIT_ViewWindow* vw = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
2012-10-08 17:16:36 +06:00
((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->Erase(myLengthPrs, true);
2012-08-09 13:58:02 +06:00
((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->Erase(myAnglePrs, true);
2012-10-08 17:16:36 +06:00
2012-08-09 13:58:02 +06:00
if (myPrsTypeList.back() != NONE)
{
// Remove last prepended IO
2012-10-08 17:16:36 +06:00
removeLastIOFromPrs(TYPE_LENGTH);
}
if (myPrsTypeList.back() == TYPE_ANGLE ||
myPrsTypeList.back() == TYPE_TWO_ANGLES)
2012-08-09 13:58:02 +06:00
{
// Remove first Angle IO from presentation
2012-10-08 17:16:36 +06:00
removeLastIOFromPrs(TYPE_ANGLE);
if (myPrsTypeList.back() == TYPE_TWO_ANGLES)
2012-08-09 13:58:02 +06:00
{
// Remove second Angle IO
2012-10-08 17:16:36 +06:00
removeLastIOFromPrs(TYPE_ANGLE);
2012-08-09 13:58:02 +06:00
}
}
2012-10-08 17:16:36 +06:00
2012-08-09 13:58:02 +06:00
// Erase last action type and store it in redo list
myPrsTypeRedoList.push_back(myPrsTypeList.back());
myPrsTypeList.pop_back();
2012-10-08 17:16:36 +06:00
2012-08-09 13:58:02 +06:00
// Display modified presentation
if (isLengthVisible)
((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->Display(myLengthPrs);
if (isAngleVisible)
((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->Display(myAnglePrs);
2012-10-08 17:16:36 +06:00
// Update of point coordinates in the control groupbox
UpdatePointCoordinates();
2012-08-09 13:58:02 +06:00
updateViewer();
2009-02-13 17:16:39 +05:00
}
}
//=================================================================================
// function : ClickOnRedo()
// purpose :
//=================================================================================
void EntityGUI_3DSketcherDlg::ClickOnRedo()
{
2012-10-08 17:16:36 +06:00
if (myRedoList.count() > 0) {
myPointsList.append(myRedoList.takeLast());
2009-02-13 17:16:39 +05:00
UpdateButtonsState();
2012-10-08 17:16:36 +06:00
GEOMBase_Helper::displayPreview(true, false, true, true, myLineWidth);
2012-08-09 13:58:02 +06:00
// Erase dimensions presentations
SUIT_ViewWindow* vw = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->Erase(myLengthPrs, true);
((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->Erase(myAnglePrs, true);
2012-10-08 17:16:36 +06:00
if (myPrsTypeRedoList.back() != NONE)
restoreLastIOToPrs(TYPE_LENGTH);
if (myPrsTypeRedoList.back() == TYPE_ANGLE ||
myPrsTypeRedoList.back() == TYPE_TWO_ANGLES)
2012-08-09 13:58:02 +06:00
{
// Add a first IO from the Redo list
2012-10-08 17:16:36 +06:00
restoreLastIOToPrs(TYPE_ANGLE);
if (myPrsTypeRedoList.back() == TYPE_TWO_ANGLES)
2012-08-09 13:58:02 +06:00
{
// Add a second IO from the Redo list
2012-10-08 17:16:36 +06:00
restoreLastIOToPrs(TYPE_ANGLE);
2012-08-09 13:58:02 +06:00
}
}
2012-10-08 17:16:36 +06:00
2012-08-09 13:58:02 +06:00
// Record last prs type
myPrsTypeList.push_back(myPrsTypeRedoList.back());
myPrsTypeRedoList.pop_back();
2012-10-08 17:16:36 +06:00
2012-08-09 13:58:02 +06:00
// Display modified presentation
if (isLengthVisible)
((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->Display(myLengthPrs);
if (isAngleVisible)
((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->Display(myAnglePrs);
2012-10-08 17:16:36 +06:00
// Update of point coordinates in the control groupbox
UpdatePointCoordinates();
2012-08-09 13:58:02 +06:00
updateViewer();
2009-02-13 17:16:39 +05:00
}
}
2012-08-09 13:58:02 +06:00
//=================================================================================
// function : removeLastIO()
// purpose :
//=================================================================================
2012-10-08 17:16:36 +06:00
void EntityGUI_3DSketcherDlg::removeLastIOFromPrs (int type)
2012-08-09 13:58:02 +06:00
{
AIS_ListOfInteractive anIOList;
2012-10-08 17:16:36 +06:00
2012-08-09 13:58:02 +06:00
if (type == TYPE_LENGTH)
{
myLengthPrs->GetObjects(anIOList);
myLengthIORedoList.Prepend(anIOList.First()); // Store last prepended Length IO in redo list
myLengthPrs->RemoveFirst(); // Remove it from myLengthPrs
2012-10-08 17:16:36 +06:00
}
2012-08-09 13:58:02 +06:00
if (type == TYPE_ANGLE)
{
myAnglePrs->GetObjects(anIOList);
myAngleIORedoList.Prepend(anIOList.First()); // Store last prepended Angle IO in redo list
myAnglePrs->RemoveFirst(); // Remove it from myAnglePrs
2012-10-08 17:16:36 +06:00
}
2012-08-09 13:58:02 +06:00
}
//=================================================================================
// function : restoreLastIO()
// purpose :
//=================================================================================
2012-10-08 17:16:36 +06:00
void EntityGUI_3DSketcherDlg::restoreLastIOToPrs (int type)
2012-08-09 13:58:02 +06:00
{
if (type == TYPE_LENGTH)
{
myLengthPrs->PrependObject(myLengthIORedoList.First()); // Restore last removed IO
myLengthIORedoList.RemoveFirst(); // Remove it from redo list
2012-10-08 17:16:36 +06:00
}
2012-08-09 13:58:02 +06:00
if (type == TYPE_ANGLE)
{
myAnglePrs->PrependObject(myAngleIORedoList.First()); // Restore last removed IO
myAngleIORedoList.RemoveFirst(); // Remove it from redo list
2012-10-08 17:16:36 +06:00
}
2012-08-09 13:58:02 +06:00
}
2009-02-13 17:16:39 +05:00
//=================================================================================
// function : SelectionIntoArgument()
// purpose : Called when selection as changed
//=================================================================================
void EntityGUI_3DSketcherDlg::SelectionIntoArgument()
{
LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
SALOME_ListIO aSelList;
aSelMgr->selectedObjects(aSelList);
int nbSel = aSelList.Extent();
2012-10-08 17:16:36 +06:00
if (nbSel == 1) {
GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject(aSelList.First());
if (!CORBA::is_nil(aSelectedObject)) {
2009-02-13 17:16:39 +05:00
TopoDS_Shape aShape;
2012-10-08 17:16:36 +06:00
if (GEOMBase::GetShape(aSelectedObject, aShape, TopAbs_SHAPE)) {
// Explore the shape if its a local selection
2012-08-09 13:58:02 +06:00
TColStd_IndexedMapOfInteger aMap;
aSelMgr->GetIndexes(aSelList.First(), aMap);
2012-10-08 17:16:36 +06:00
if (aMap.Extent() == 1) {
int anIndex = aMap(1);
GEOM::GEOM_IShapesOperations_var aShapesOp = getGeomEngine()->GetIShapesOperations(getStudyId());
aSelectedObject = aShapesOp->GetSubShape(aSelectedObject, anIndex);
}
2009-02-13 17:16:39 +05:00
}
bool isOk = true;
2012-10-08 17:16:36 +06:00
if (aShape.ShapeType() != TopAbs_VERTEX)
2012-08-09 13:58:02 +06:00
isOk = GEOMBase::GetShape(aSelectedObject, aShape, TopAbs_VERTEX);
2009-02-13 17:16:39 +05:00
if (isOk) {
2012-08-09 13:58:02 +06:00
gp_Pnt aPnt;
2012-10-08 17:16:36 +06:00
if (GEOMBase::VertexToPoint(aShape, aPnt)) {
2012-08-09 13:58:02 +06:00
// set coordinates to the Spin Boxes
double aX, aY, aZ;
aX = aPnt.X();
aY = aPnt.Y();
aZ = aPnt.Z();
bool blocked = Group3Spin->SpinBox_DX->signalsBlocked();
Group3Spin->SpinBox_DX->blockSignals(true);
Group3Spin->SpinBox_DY->blockSignals(true);
Group3Spin->SpinBox_DZ->blockSignals(true);
2012-10-08 17:16:36 +06:00
if (GroupType->RadioButton1->isChecked()) {
Group3Spin->SpinBox_DX->setValue(aX);
Group3Spin->SpinBox_DY->setValue(aY);
Group3Spin->SpinBox_DZ->setValue(aZ);
}
else if (GroupType->RadioButton2->isChecked()) {
2012-08-09 13:58:02 +06:00
XYZ xyz = getLastPoint();
2012-10-08 17:16:36 +06:00
Group3Spin->SpinBox_DX->setValue(aX - xyz.x);
Group3Spin->SpinBox_DY->setValue(aY - xyz.y);
Group3Spin->SpinBox_DZ->setValue(aZ - xyz.z);
2012-08-09 13:58:02 +06:00
}
Group3Spin->SpinBox_DX->blockSignals(blocked);
Group3Spin->SpinBox_DY->blockSignals(blocked);
Group3Spin->SpinBox_DZ->blockSignals(blocked);
}
2009-02-13 17:16:39 +05:00
}
}
}
2012-10-08 17:16:36 +06:00
GEOMBase_Helper::displayPreview(true, false, true, true, myLineWidth);
2009-02-13 17:16:39 +05:00
}
//=================================================================================
// function : DeactivateActiveDialog()
// purpose :
//=================================================================================
void EntityGUI_3DSketcherDlg::DeactivateActiveDialog()
{
2012-10-08 17:16:36 +06:00
setEnabled(false);
2009-02-13 17:16:39 +05:00
globalSelection();
2012-10-08 17:16:36 +06:00
disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
myGeomGUI->SetActiveDialogBox(0);
2009-02-13 17:16:39 +05:00
}
//=================================================================================
// function : ActivateThisDialog()
// purpose :
//=================================================================================
void EntityGUI_3DSketcherDlg::ActivateThisDialog()
{
myGeomGUI->EmitSignalDeactivateDialog();
2012-10-08 17:16:36 +06:00
setEnabled(true);
myGeomGUI->SetActiveDialogBox(this);
2009-02-13 17:16:39 +05:00
2012-10-08 17:16:36 +06:00
connect(myGeomGUI->getApp()->selectionMgr(),
SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
2009-02-13 17:16:39 +05:00
2012-10-08 17:16:36 +06:00
localSelection(GEOM::GEOM_Object::_nil(), TopAbs_VERTEX);
GEOMBase_Helper::displayPreview(true, false, true, true, myLineWidth);
2009-02-13 17:16:39 +05:00
}
//=================================================================================
// function : ValueChangedInSpinBox()
// purpose :
//=================================================================================
2012-10-08 17:16:36 +06:00
void EntityGUI_3DSketcherDlg::ValueChangedInSpinBox (double newValue)
2009-02-13 17:16:39 +05:00
{
2012-10-08 17:16:36 +06:00
GEOMBase_Helper::displayPreview(true, false, true, true, myLineWidth);
2012-08-09 13:58:02 +06:00
}
//=================================================================================
// function : BoxChecked()
// purpose : ChecBoxes management
//=================================================================================
2012-10-08 17:16:36 +06:00
void EntityGUI_3DSketcherDlg::BoxChecked (bool checked)
2012-08-09 13:58:02 +06:00
{
QCheckBox* send = (QCheckBox*) sender();
SUIT_ViewWindow* vw = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
2012-10-08 17:16:36 +06:00
2012-08-09 13:58:02 +06:00
if (send == GroupAngles->checkBox)
2012-10-08 17:16:36 +06:00
GroupAngles->SpinBox_DA2->setEnabled(checked);
2012-08-09 13:58:02 +06:00
else if (send == GroupControls->CheckBox1)
{
((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->Erase(myLengthPrs, true);
2012-10-08 17:16:36 +06:00
if (checked){
2012-08-09 13:58:02 +06:00
((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->Display(myLengthPrs);
isLengthVisible=true;
}
else
isLengthVisible=false;
}
else if (send == GroupControls->CheckBox2)
{
2012-10-08 17:16:36 +06:00
((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->Erase(myAnglePrs, true);
if (checked)
2012-08-09 13:58:02 +06:00
{
((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->Display(myAnglePrs);
isAngleVisible=true;
}
else
isAngleVisible=false;
}
2012-10-08 17:16:36 +06:00
else if (send == GroupControls->CheckBox3)
{
GroupControls->lineEdit_1->setVisible(checked);
GroupControls->lineEdit_2->setVisible(checked);
GroupControls->lineEdit_3->setVisible(checked);
GroupControls->lineEdit_4->setVisible(checked);
GroupControls->lineEdit_5->setVisible(checked);
GroupControls->lineEdit_6->setVisible(checked);
GroupControls->label_1->setVisible(checked);
GroupControls->label_2->setVisible(checked);
GroupControls->label_3->setVisible(checked);
GroupControls->label_4->setVisible(checked);
GroupControls->label_5->setVisible(checked);
GroupControls->label_6->setVisible(checked);
GroupControls->label_7->setVisible(checked);
GroupControls->label_8->setVisible(checked);
GroupControls->updateGeometry();
GroupControls->resize(minimumSizeHint());
}
2012-08-09 13:58:02 +06:00
2012-10-08 17:16:36 +06:00
updateGeometry();
resize(minimumSizeHint());
GEOMBase_Helper::displayPreview(true, false, true, true, myLineWidth);
2012-08-09 13:58:02 +06:00
}
//=================================================================================
// function : ButtonClicked()
// purpose :
//=================================================================================
2012-10-08 17:16:36 +06:00
void EntityGUI_3DSketcherDlg::ButtonClicked (bool checked)
2012-08-09 13:58:02 +06:00
{
if (GroupAngles->radioButton_1->isChecked())
2012-10-08 17:16:36 +06:00
myOrientation = OXY;
2012-08-09 13:58:02 +06:00
else if (GroupAngles->radioButton_2->isChecked())
2012-10-08 17:16:36 +06:00
myOrientation = OYZ;
2012-08-09 13:58:02 +06:00
else
2012-10-08 17:16:36 +06:00
myOrientation = OXZ;
GEOMBase_Helper::displayPreview(true, false, true, true, myLineWidth);
2009-02-13 17:16:39 +05:00
}
//=================================================================================
// function : enterEvent()
// purpose :
//=================================================================================
2012-10-08 17:16:36 +06:00
void EntityGUI_3DSketcherDlg::enterEvent (QEvent*)
2009-02-13 17:16:39 +05:00
{
2012-10-08 17:16:36 +06:00
if (!mainFrame()->GroupConstructors->isEnabled())
2009-02-13 17:16:39 +05:00
ActivateThisDialog();
}
//=================================================================================
// function : createOperation
// purpose :
//=================================================================================
GEOM::GEOM_IOperations_ptr EntityGUI_3DSketcherDlg::createOperation()
{
2012-10-08 17:16:36 +06:00
return getGeomEngine()->GetICurvesOperations(getStudyId());
2009-02-13 17:16:39 +05:00
}
//=================================================================================
// function : isValid
// purpose :
//=================================================================================
2012-10-08 17:16:36 +06:00
bool EntityGUI_3DSketcherDlg::isValid (QString& msg)
2009-02-13 17:16:39 +05:00
{
2012-08-09 13:58:02 +06:00
bool ok = true;
2012-10-08 17:16:36 +06:00
ok = Group3Spin->SpinBox_DX->isValid(msg, !IsPreview()) && ok;
ok = Group3Spin->SpinBox_DY->isValid(msg, !IsPreview()) && ok;
ok = Group3Spin->SpinBox_DZ->isValid(msg, !IsPreview()) && ok;
2012-08-09 13:58:02 +06:00
return ok;
2009-02-13 17:16:39 +05:00
}
//=================================================================================
// function : execute
// purpose :
//=================================================================================
2012-10-08 17:16:36 +06:00
bool EntityGUI_3DSketcherDlg::execute (ObjectList& objects)
2009-02-13 17:16:39 +05:00
{
2012-10-08 17:16:36 +06:00
//GEOM::ListOfDouble_var aCoordsArray = new GEOM::ListOfDouble;
//if (!myOK || myPointsList.size() == 0)
// aCoordsArray->length((myPointsList.size()+1)*3);
//else
// aCoordsArray->length(myPointsList.size()*3);
QStringList aCommands;
aCommands << "3DSketcher";
2012-08-09 13:58:02 +06:00
QStringList aParameters;
2009-02-13 17:16:39 +05:00
2012-10-08 17:16:36 +06:00
//int i = 0;
2012-08-09 13:58:02 +06:00
QList<XYZ>::const_iterator it;
2012-10-08 17:16:36 +06:00
for (it = myPointsList.begin(); it != myPointsList.end(); ++it) {
//aCoordsArray[i++] = (*it).x;
//aCoordsArray[i++] = (*it).y;
//aCoordsArray[i++] = (*it).z;
aCommands << (*it).command;
aParameters << (*it).params;
2009-02-13 17:16:39 +05:00
}
if (!myOK || myPointsList.size() == 0) {
2012-08-09 13:58:02 +06:00
XYZ xyz = getCurrentPoint();
2012-10-08 17:16:36 +06:00
//aCoordsArray[i++] = xyz.x;
//aCoordsArray[i++] = xyz.y;
//aCoordsArray[i++] = xyz.z;
aCommands << xyz.command;
aParameters << xyz.params;
}
2009-02-13 17:16:39 +05:00
2012-08-09 13:58:02 +06:00
GEOM::GEOM_ICurvesOperations_var anOper = GEOM::GEOM_ICurvesOperations::_narrow(getOperation());
2012-10-08 17:16:36 +06:00
//GEOM::GEOM_Object_var anObj = anOper->Make3DSketcher(aCoordsArray);
GEOM::GEOM_Object_var anObj = anOper->Make3DSketcherCommand(aCommands.join(":").toLatin1().constData());
2009-02-13 17:16:39 +05:00
2012-10-08 17:16:36 +06:00
if (!anObj->_is_nil()) {
if (!IsPreview()) anObj->SetParameters(aParameters.join(":").toLatin1().constData());
objects.push_back(anObj._retn());
2012-08-09 13:58:02 +06:00
}
2009-02-13 17:16:39 +05:00
return true;
}
//=================================================================================
// function : SetDoubleSpinBoxStep()
// purpose : Double spin box management
//=================================================================================
2012-10-08 17:16:36 +06:00
void EntityGUI_3DSketcherDlg::SetDoubleSpinBoxStep (double step)
2009-02-13 17:16:39 +05:00
{
Group3Spin->SpinBox_DX->setSingleStep(step);
Group3Spin->SpinBox_DY->setSingleStep(step);
Group3Spin->SpinBox_DZ->setSingleStep(step);
2012-08-09 13:58:02 +06:00
GroupAngles->SpinBox_DA->setSingleStep(step);
GroupAngles->SpinBox_DL->setSingleStep(step);
GroupAngles->SpinBox_DA2->setSingleStep(step);
2009-02-13 17:16:39 +05:00
}
//=================================================================================
// function : ClickOnOk()
// purpose :
//=================================================================================
void EntityGUI_3DSketcherDlg::ClickOnOk()
{
2012-10-08 17:16:36 +06:00
Locker lock(myOK);
2009-02-13 17:16:39 +05:00
2012-10-08 17:16:36 +06:00
if (!onAccept())
2009-02-13 17:16:39 +05:00
return;
ClickOnCancel();
}
//=================================================================================
// function : ClickOnApply()
// purpose :
//=================================================================================
bool EntityGUI_3DSketcherDlg::ClickOnApply()
{
2012-08-09 13:58:02 +06:00
QString msg;
2012-10-08 17:16:36 +06:00
if (!isValid(msg)) {
showError(msg);
2012-08-09 13:58:02 +06:00
return false;
2009-02-13 17:16:39 +05:00
}
2012-08-09 13:58:02 +06:00
if (myPointsList.count() > 0)
myPointsList.append(myPointsList[0]);
2012-10-08 17:16:36 +06:00
Locker lock(myOK);
2009-02-13 17:16:39 +05:00
2012-10-08 17:16:36 +06:00
if (!onAccept())
2009-02-13 17:16:39 +05:00
return false;
2012-10-08 17:16:36 +06:00
2009-02-13 17:16:39 +05:00
ClickOnCancel();
return true;
}
//=================================================================================
2012-08-09 13:58:02 +06:00
// function : getLastPoint()
2009-02-13 17:16:39 +05:00
// purpose : return last points from list
//=================================================================================
2012-08-09 13:58:02 +06:00
EntityGUI_3DSketcherDlg::XYZ EntityGUI_3DSketcherDlg::getLastPoint() const
{
return myPointsList.count() > 0 ? myPointsList.last() : XYZ();
}
//=================================================================================
// function : getPenultimatePoint()
// purpose : return penultimate point from list
//=================================================================================
EntityGUI_3DSketcherDlg::XYZ EntityGUI_3DSketcherDlg::getPenultimatePoint() const
2009-02-13 17:16:39 +05:00
{
2012-08-09 13:58:02 +06:00
double size = myPointsList.count();
return size > 1 ? myPointsList.at(size - 2) : XYZ();
2009-02-13 17:16:39 +05:00
}
//=================================================================================
2012-08-09 13:58:02 +06:00
// function : getCurrentPoint()
2012-10-08 17:16:36 +06:00
// purpose : returns current point
2009-02-13 17:16:39 +05:00
//=================================================================================
2012-08-09 13:58:02 +06:00
EntityGUI_3DSketcherDlg::XYZ EntityGUI_3DSketcherDlg::getCurrentPoint() const
2009-02-13 17:16:39 +05:00
{
2012-10-08 17:16:36 +06:00
XYZ xyz;
SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
int aPrecision = resMgr->integerValue("Geometry", "length_precision", 7);
if (myMode == 2) {
if (GroupAngles->radioButton_1->isChecked())
xyz.command = "OXY ";
else if (GroupAngles->radioButton_2->isChecked())
xyz.command = "OYZ ";
else
xyz.command = "OXZ ";
double anAngle = GroupAngles->SpinBox_DA->value();
2012-08-09 13:58:02 +06:00
double aLength = GroupAngles->SpinBox_DL->value();
2012-10-08 17:16:36 +06:00
double anAngle2 = 0.0;
QString da2 = "0";
if (GroupAngles->checkBox->isChecked()) {
anAngle2 = GroupAngles->SpinBox_DA2->value();
da2 = GroupAngles->SpinBox_DA2->text();
}
xyz.command +=
QString::number(anAngle, 'g', aPrecision) + " " +
QString::number(anAngle2, 'g', aPrecision) + " " +
QString::number(aLength, 'g', aPrecision);
xyz.params =
GroupAngles->SpinBox_DA->text() + ":" +
da2 + ":" +
GroupAngles->SpinBox_DL->text();
// Calculate point coordinates for preview
anAngle = anAngle * M_PI/180.0;
anAngle2 = anAngle2 * M_PI/180.0;
2012-08-09 13:58:02 +06:00
double aProjectedLength = aLength * cos(anAngle2);
2012-10-08 17:16:36 +06:00
XYZ xyzP = getLastPoint();
if (GroupAngles->radioButton_1->isChecked()) // OXY
2012-08-09 13:58:02 +06:00
{
2012-10-08 17:16:36 +06:00
xyz.x = xyzP.x + aProjectedLength * cos(anAngle);
xyz.y = xyzP.y + aProjectedLength * sin(anAngle);
xyz.z = xyzP.z + aLength * sin(anAngle2);
2012-08-09 13:58:02 +06:00
}
2012-10-08 17:16:36 +06:00
else if (GroupAngles->radioButton_2->isChecked()) // OYZ
2012-08-09 13:58:02 +06:00
{
2012-10-08 17:16:36 +06:00
xyz.y = xyzP.y + aProjectedLength * cos(anAngle);
xyz.z = xyzP.z + aProjectedLength * sin(anAngle);
xyz.x = xyzP.x + aLength * sin(anAngle2);
2012-08-09 13:58:02 +06:00
}
2012-10-08 17:16:36 +06:00
else // OXZ
2012-08-09 13:58:02 +06:00
{
2012-10-08 17:16:36 +06:00
xyz.z = xyzP.z + aProjectedLength * sin(anAngle);
xyz.x = xyzP.x + aProjectedLength * cos(anAngle);
xyz.y = xyzP.y + aLength * sin(anAngle2);
2012-08-09 13:58:02 +06:00
}
}
2012-10-08 17:16:36 +06:00
else {
if (myMode == 0) { // XYZ
2012-08-09 13:58:02 +06:00
xyz.x = Group3Spin->SpinBox_DX->value();
xyz.y = Group3Spin->SpinBox_DY->value();
xyz.z = Group3Spin->SpinBox_DZ->value();
2012-10-08 17:16:36 +06:00
xyz.command = "TT ";
}
else { // DXDYDZ
2012-08-09 13:58:02 +06:00
xyz = getLastPoint();
xyz.x += Group3Spin->SpinBox_DX->value();
xyz.y += Group3Spin->SpinBox_DY->value();
xyz.z += Group3Spin->SpinBox_DZ->value();
2012-10-08 17:16:36 +06:00
xyz.command = "T ";
2012-08-09 13:58:02 +06:00
}
2012-10-08 17:16:36 +06:00
double aX = Group3Spin->SpinBox_DX->value();
double aY = Group3Spin->SpinBox_DY->value();
double aZ = Group3Spin->SpinBox_DZ->value();
xyz.command +=
QString::number(aX, 'g', aPrecision) + " " +
QString::number(aY, 'g', aPrecision) + " " +
QString::number(aZ, 'g', aPrecision);
xyz.params =
Group3Spin->SpinBox_DX->text() + ":" +
Group3Spin->SpinBox_DY->text() + ":" +
Group3Spin->SpinBox_DZ->text();
2009-02-13 17:16:39 +05:00
}
2012-08-09 13:58:02 +06:00
return xyz;
2009-02-13 17:16:39 +05:00
}
//================================================================
// Function : displayPreview
// Purpose : Method for displaying preview of resulting shape
// Redefined from GEOMBase_Helper.
//================================================================
2012-10-08 17:16:36 +06:00
void EntityGUI_3DSketcherDlg::displayPreview (GEOM::GEOM_Object_ptr object,
2012-08-09 13:58:02 +06:00
const bool append,
const bool activate,
const bool update,
const double lineWidth,
const int displayMode,
2012-10-08 17:16:36 +06:00
const int color)
{
SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
2012-08-09 13:58:02 +06:00
QColor aColor = resMgr->colorValue("Geometry","line_color",QColor(255,0,0));
2012-10-08 17:16:36 +06:00
Quantity_NameOfColor line_color = SalomeApp_Tools::color(aColor).Name();
2009-02-13 17:16:39 +05:00
// set width of displayed shape
2012-08-09 13:58:02 +06:00
int lw = lineWidth;
2012-10-08 17:16:36 +06:00
if (lw == -1) {
2012-08-09 13:58:02 +06:00
lw = resMgr->integerValue("Geometry", "preview_edge_width", -1);
}
2012-10-08 17:16:36 +06:00
getDisplayer()->SetWidth(lw);
2009-02-13 17:16:39 +05:00
// Disable activation of selection
2012-10-08 17:16:36 +06:00
getDisplayer()->SetToActivate(activate);
2009-02-13 17:16:39 +05:00
// Make a reference to GEOM_Object
2012-10-08 17:16:36 +06:00
CORBA::String_var objStr = myGeometryGUI->getApp()->orb()->object_to_string(object);
getDisplayer()->SetName(objStr.in());
2009-02-13 17:16:39 +05:00
2012-08-09 13:58:02 +06:00
// Create wire from applied object
2009-02-13 17:16:39 +05:00
TopoDS_Shape anApplyedWire, aLastSegment;
2012-10-08 17:16:36 +06:00
if (!createShapes(object, anApplyedWire, aLastSegment))
2009-02-13 17:16:39 +05:00
return;
2012-08-09 13:58:02 +06:00
// Set color for preview shape
2012-10-08 17:16:36 +06:00
getDisplayer()->SetColor(line_color);
2009-02-13 17:16:39 +05:00
// Build prs
2012-10-08 17:16:36 +06:00
SALOME_Prs* aPrs = getDisplayer()->BuildPrs(anApplyedWire);
if (aPrs != 0 && !aPrs->IsNull())
GEOMBase_Helper::displayPreview(aPrs, append, update);
getDisplayer()->SetColor(Quantity_NOC_VIOLET);
aPrs = getDisplayer()->BuildPrs(aLastSegment);
if (aPrs != 0 && !aPrs->IsNull())
GEOMBase_Helper::displayPreview(aPrs, append, update);
getDisplayer()->SetColor(line_color);
2009-02-13 17:16:39 +05:00
2012-08-09 13:58:02 +06:00
// Display local trihedron if the mode is relatives coordinates or angles
if (myMode == 1 || myMode == 2)
displayTrihedron(2);
2012-10-08 17:16:36 +06:00
2012-08-09 13:58:02 +06:00
// Display preview of suitable dimension presentations
2012-10-08 17:16:36 +06:00
if (myMode == 2) // ANGLES
2012-08-09 13:58:02 +06:00
{
double anAngle2 = 0.0;
if (GroupAngles->checkBox->isChecked())
anAngle2 = GroupAngles->SpinBox_DA2->value();
2012-10-08 17:16:36 +06:00
2012-08-09 13:58:02 +06:00
displayAngle(GroupAngles->SpinBox_DA->value(), anAngle2, GroupAngles->SpinBox_DL->value(), myOrientation);
2012-10-08 17:16:36 +06:00
displayLength(GroupAngles->SpinBox_DL->value(), /*store=*/false, /*type=*/myPrsType);
2012-08-09 13:58:02 +06:00
}
2012-10-08 17:16:36 +06:00
if (myMode == 0 || myMode == 1) // COORDINATES
displayLength();
2009-02-13 17:16:39 +05:00
getDisplayer()->UnsetName();
// Enable activation of displayed objects
2012-10-08 17:16:36 +06:00
getDisplayer()->SetToActivate(true);
2009-02-13 17:16:39 +05:00
}
2012-08-09 13:58:02 +06:00
//================================================================
// Function : displayTrihedron()
// Purpose : Method for displaying trihedron
//================================================================
2012-10-08 17:16:36 +06:00
void EntityGUI_3DSketcherDlg::displayTrihedron (int selMode)
2012-08-09 13:58:02 +06:00
{
// Add trihedron to preview
SUIT_ViewWindow* vw = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
2012-10-08 17:16:36 +06:00
2012-08-09 13:58:02 +06:00
gp_Pnt P(getLastPoint().x,getLastPoint().y,getLastPoint().z);
Handle(Geom_Axis2Placement) anAxis = new Geom_Axis2Placement(P,gp::DZ(),gp::DX());
Handle(AIS_Trihedron) anIO = new AIS_Trihedron(anAxis);
anIO->SetSelectionMode(selMode);
2012-10-08 17:16:36 +06:00
SOCC_Prs* aSPrs = dynamic_cast<SOCC_Prs*>
(((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->CreatePrs(0));
if (aSPrs) {
2012-08-09 13:58:02 +06:00
aSPrs->PrependObject(anIO);
2012-10-08 17:16:36 +06:00
GEOMBase_Helper::displayPreview(aSPrs, true, true);
2012-08-09 13:58:02 +06:00
}
}
//================================================================
// Function : displayAngle()
// Purpose : Method for displaying angle dimensions
//================================================================
2012-10-08 17:16:36 +06:00
void EntityGUI_3DSketcherDlg::displayAngle (double theAngle1, double theAngle2,
double theLength, int theOrientation, bool store)
2012-08-09 13:58:02 +06:00
{
2012-10-08 17:16:36 +06:00
if (Abs(theAngle2 - 90.0) < Precision::Angular() ||
theLength < Precision::Confusion())
2012-08-09 13:58:02 +06:00
return;
2012-10-08 17:16:36 +06:00
SUIT_ViewWindow* vw = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
2012-08-09 13:58:02 +06:00
XYZ Last = getLastPoint();
XYZ Current = getCurrentPoint();
2012-10-08 17:16:36 +06:00
2012-08-09 13:58:02 +06:00
gp_Pnt Last_Pnt(Last.x,Last.y,Last.z);
gp_Pnt Current_Pnt(Current.x,Current.y,Current.z);
gp_Pnt P1, P2;
2012-10-08 17:16:36 +06:00
2012-08-09 13:58:02 +06:00
bool twoAngles = GroupAngles->checkBox->isChecked();
2012-10-08 17:16:36 +06:00
2012-08-09 13:58:02 +06:00
switch(theOrientation)
{
2012-10-08 17:16:36 +06:00
case OXY:
{
2012-08-09 13:58:02 +06:00
P1 = gp_Pnt(Last.x + theLength,Last.y,Last.z); // X direction
P2 = gp_Pnt(Last.x + theLength * cos(theAngle1 * M_PI / 180.),
Last.y + theLength * sin(theAngle1 * M_PI / 180.),
2012-10-08 17:16:36 +06:00
Last.z);
2012-08-09 13:58:02 +06:00
break;
}
2012-10-08 17:16:36 +06:00
case OYZ:
2012-08-09 13:58:02 +06:00
{
P1 = gp_Pnt(Last.x, Last.y + theLength,Last.z); // Y direction
2012-10-08 17:16:36 +06:00
P2 = gp_Pnt(Last.x,
2012-08-09 13:58:02 +06:00
Last.y + theLength * cos(theAngle1 * M_PI / 180.),
2012-10-08 17:16:36 +06:00
Last.z + theLength * sin(theAngle1 * M_PI / 180.));
2012-08-09 13:58:02 +06:00
break;
}
2012-10-08 17:16:36 +06:00
case OXZ:
2012-08-09 13:58:02 +06:00
{
2012-10-08 17:16:36 +06:00
P1 = gp_Pnt(Last.x + theLength,Last.y,Last.z); // X direction
P2 = gp_Pnt(Last.x + theLength * cos(theAngle1 * M_PI / 180.) ,
Last.y,
Last.z + theLength * sin(theAngle1 * M_PI / 180.));
2012-08-09 13:58:02 +06:00
break;
}
}
2012-10-08 17:16:36 +06:00
2012-08-09 13:58:02 +06:00
TopoDS_Vertex V1 = BRepBuilderAPI_MakeVertex(P1);
TopoDS_Vertex V2 = BRepBuilderAPI_MakeVertex(P2);
TopoDS_Vertex LastV = BRepBuilderAPI_MakeVertex(Last_Pnt);
TopoDS_Vertex CurV = BRepBuilderAPI_MakeVertex(Current_Pnt);
TopoDS_Edge anEdge1 = BRepBuilderAPI_MakeEdge(LastV, V1);
TopoDS_Edge anEdge2 = BRepBuilderAPI_MakeEdge(LastV, V2);
TopoDS_Edge anEdge3 = BRepBuilderAPI_MakeEdge(LastV, CurV);
2012-10-08 17:16:36 +06:00
gce_MakePln gce_MP (Last_Pnt, P1, P2);
Handle(Geom_Plane) aPlane = new Geom_Plane(gce_MP.Value());
// Convert angles to string
2012-08-09 13:58:02 +06:00
std::string Angle1_str = doubleToString(theAngle1);
std::string Angle2_str = doubleToString(theAngle2);
2012-10-08 17:16:36 +06:00
2012-08-09 13:58:02 +06:00
// Create interactive object
2012-10-08 17:16:36 +06:00
Handle(AIS_AngleDimension) anAngleIO = new AIS_AngleDimension
(anEdge1, anEdge2, aPlane, theAngle1 * M_PI / 180.,
TCollection_ExtendedString(Angle1_str.c_str()));
anAngleIO->SetArrowSize((theAngle1 * M_PI / 180) * (theLength/20));
2012-08-09 13:58:02 +06:00
SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
int w = resMgr->integerValue("Geometry", "measures_line_width", 1);
2012-10-08 17:16:36 +06:00
2012-08-09 13:58:02 +06:00
Handle(Prs3d_AngleAspect) asp = new Prs3d_AngleAspect();
asp->LineAspect()->SetWidth(w);
anAngleIO->Attributes()->SetAngleAspect(asp);
2012-10-08 17:16:36 +06:00
SOCC_Prs* aSPrs = dynamic_cast<SOCC_Prs*>
(((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->CreatePrs(0));
2012-08-09 13:58:02 +06:00
if (store)
{
// Erase dimensions presentations
((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->Erase(myAnglePrs, true);
myAnglePrs->PrependObject(anAngleIO);
2012-10-08 17:16:36 +06:00
2012-08-09 13:58:02 +06:00
// Display modified presentation
if (isAngleVisible)
((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->Display(myAnglePrs);
}
2012-10-08 17:16:36 +06:00
else if (aSPrs)
2012-08-09 13:58:02 +06:00
{
aSPrs->AddObject(anAngleIO);
}
2012-10-08 17:16:36 +06:00
myPrsType = TYPE_ANGLE; // Overwrite type with ANGLE
2012-08-09 13:58:02 +06:00
if (twoAngles)
{
gce_MakePln gce_MP2(Last_Pnt, P2, Current_Pnt);
Handle(Geom_Plane) aPlane2 = new Geom_Plane(gce_MP2.Value());
2012-10-08 17:16:36 +06:00
Handle(AIS_AngleDimension) anAngle2IO =
new AIS_AngleDimension(anEdge2, anEdge3, aPlane2, theAngle2 * M_PI / 180.,
TCollection_ExtendedString(Angle2_str.c_str()));
anAngle2IO->SetArrowSize((theAngle2 * M_PI / 180) * (theLength/20));
2012-08-09 13:58:02 +06:00
anAngle2IO->Attributes()->SetAngleAspect(asp);
2012-10-08 17:16:36 +06:00
2012-08-09 13:58:02 +06:00
if (store)
{
// Erase dimensions presentations
((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->Erase(myAnglePrs, true);
myAnglePrs->PrependObject(anAngle2IO);
2012-10-08 17:16:36 +06:00
2012-08-09 13:58:02 +06:00
// Display modified presentation
if (isAngleVisible)
((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->Display(myAnglePrs);
}
else if (aSPrs)
{
2012-10-08 17:16:36 +06:00
aSPrs->AddObject(anAngle2IO);
2012-08-09 13:58:02 +06:00
}
2012-10-08 17:16:36 +06:00
myPrsType = TYPE_TWO_ANGLES; // Overwrite type with TWO_ANGLES
2012-08-09 13:58:02 +06:00
}
2012-10-08 17:16:36 +06:00
if (!store && isAngleVisible)
{
GEOMBase_Helper::displayPreview(aSPrs, true, true);
2012-08-09 13:58:02 +06:00
}
}
//================================================================
// Function : displayLength()
// Purpose : Method for displaying length dimensions
//================================================================
2012-10-08 17:16:36 +06:00
void EntityGUI_3DSketcherDlg::displayLength (double theLength, bool store, int type)
2012-08-09 13:58:02 +06:00
{
SUIT_ViewWindow* vw = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
2012-10-08 17:16:36 +06:00
2012-08-09 13:58:02 +06:00
XYZ Last = getLastPoint();
XYZ Current = getCurrentPoint();
XYZ Penultimate = getPenultimatePoint();
2012-10-08 17:16:36 +06:00
bool withAngle = (type == TYPE_ANGLE || type == TYPE_TWO_ANGLES);
bool twoAngles = (type == TYPE_TWO_ANGLES);
2012-08-09 13:58:02 +06:00
2012-10-08 17:16:36 +06:00
double aLength = 0.0;
if (theLength < 0) // Calculate length if not given
2012-08-09 13:58:02 +06:00
{
aLength = sqrt((Last.x - Current.x)*(Last.x - Current.x) +
2012-10-08 17:16:36 +06:00
(Last.y - Current.y)*(Last.y - Current.y) +
2012-08-09 13:58:02 +06:00
(Last.z - Current.z)*(Last.z - Current.z));
}
else
aLength = theLength;
2012-10-08 17:16:36 +06:00
2012-08-09 13:58:02 +06:00
if (aLength<Precision::Confusion())
return;
2012-10-08 17:16:36 +06:00
2012-08-09 13:58:02 +06:00
gp_Pnt P1 = gp_Pnt(Last.x,Last.y,Last.z);
gp_Pnt P2 = gp_Pnt(Current.x,Current.y,Current.z);
gp_Pnt P3 = gp_Pnt(Penultimate.x,Penultimate.y,Penultimate.z);
2012-10-08 17:16:36 +06:00
2012-08-09 13:58:02 +06:00
gp_Vec Vec1(P1,P2);
gp_Vec Vec2(P1,P3);
2012-10-08 17:16:36 +06:00
gp_Vec Vec3 = Vec1;
2012-08-09 13:58:02 +06:00
TopoDS_Vertex aVert1 = BRepBuilderAPI_MakeVertex(P1);
TopoDS_Vertex aVert2 = BRepBuilderAPI_MakeVertex(P2);
2012-10-08 17:16:36 +06:00
2012-08-09 13:58:02 +06:00
// Convert length to string
std::string aLength_str = doubleToString(aLength);
2012-10-08 17:16:36 +06:00
// Define the suitable plane for right relative positioning of dimension presentations
gp_Dir aNormal; // Normal defining the plane of the presentation
if (withAngle) // If one angle
2012-08-09 13:58:02 +06:00
{
2012-10-08 17:16:36 +06:00
switch(myOrientation)
2012-08-09 13:58:02 +06:00
{
2012-10-08 17:16:36 +06:00
case OXY:
{
aNormal = gp::DZ().Crossed(gp_Dir(Vec1));//--> the plane is orthogonal to the angle presentation
// plane and contains the current edge
if (twoAngles) // If two angles
{
gp_XYZ Vec1_XY(Vec1.X(),Vec1.Y(),0.0);// --> define Vec3 as the projection of the current
Vec3 = gp_Vec(Vec1_XY); // edge on the plane chosen for the first angle
}
break;
}
case OYZ:
{
aNormal = gp::DX().Crossed(gp_Dir(Vec1));
if (twoAngles)
{
gp_XYZ Vec1_YZ(0.0,Vec1.Y(),Vec1.Z());
Vec3 = gp_Vec(Vec1_YZ);
}
break;
}
case OXZ:
{
aNormal = gp::DY().Crossed(gp_Dir(Vec1));
if (twoAngles)
{
gp_XYZ Vec1_XZ(Vec1.X(),0.0,Vec1.Z());
Vec3 = gp_Vec(Vec1_XZ);
}
break;
}
2012-08-09 13:58:02 +06:00
}
2012-10-08 17:16:36 +06:00
if(twoAngles // If two angles
&& Abs(Vec1.CrossMagnitude(Vec3)) > Precision::Confusion())
{
aNormal = gp_Dir(Vec1.Crossed(Vec3));// --> set the normal as the cross product of
} // the current edge with its projection
} // it ensures that the dimension changes
else
{
// Check colinearity
if (Abs(Vec1.CrossMagnitude(Vec2)) < Precision::Confusion())
{
Vec2 = gp_Vec(gp::DX());
if (Abs(Vec1.CrossMagnitude(Vec2)) < Precision::Confusion())
{
Vec2 = gp_Vec(gp::DY());
}
}
aNormal = gp_Dir(Vec1.Crossed(Vec2)); // If no angles --> the plane is the one formed by
} // the last edge and the current one
2012-08-09 13:58:02 +06:00
2012-10-08 17:16:36 +06:00
// Plane construction
gce_MakePln gce_MP(P1, aNormal);
2012-08-09 13:58:02 +06:00
Handle(Geom_Plane) aPlane = new Geom_Plane(gce_MP.Value());
2012-10-08 17:16:36 +06:00
Handle(AIS_LengthDimension) anIO =
new AIS_LengthDimension(aVert1,
aVert2,
aPlane,
aLength,
TCollection_ExtendedString(aLength_str.c_str()));
2012-08-09 13:58:02 +06:00
anIO->SetArrowSize(aLength/20);
2012-10-08 17:16:36 +06:00
2012-08-09 13:58:02 +06:00
SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
int w = resMgr->integerValue("Geometry", "measures_line_width", 1);
Handle(Prs3d_LengthAspect) asp = new Prs3d_LengthAspect();
asp->LineAspect()->SetWidth(w);
anIO->Attributes()->SetLengthAspect(asp);
2012-10-08 17:16:36 +06:00
2012-08-09 13:58:02 +06:00
if (store)
{
// Erase length dimensions presentation
((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->Erase(myLengthPrs, true);
myLengthPrs->PrependObject(anIO);
2012-10-08 17:16:36 +06:00
2012-08-09 13:58:02 +06:00
// Display modified presentation
if (isLengthVisible)
((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->Display(myLengthPrs);
}
2012-10-08 17:16:36 +06:00
else if (isLengthVisible)
2012-08-09 13:58:02 +06:00
{
2012-10-08 17:16:36 +06:00
SOCC_Prs* aSPrs = dynamic_cast<SOCC_Prs*>
(((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->CreatePrs(0));
2012-08-09 13:58:02 +06:00
if (aSPrs)
{
aSPrs->PrependObject(anIO);
2012-10-08 17:16:36 +06:00
GEOMBase_Helper::displayPreview(aSPrs, true, true);
2012-08-09 13:58:02 +06:00
}
}
2012-10-08 17:16:36 +06:00
myPrsType = TYPE_LENGTH;
2012-08-09 13:58:02 +06:00
}
2009-02-13 17:16:39 +05:00
//================================================================
// Function : createShapes
// Purpose : Create applyed wire, and last segment from entry object
//================================================================
2012-10-08 17:16:36 +06:00
bool EntityGUI_3DSketcherDlg::createShapes (GEOM::GEOM_Object_ptr /*theObject*/,
2012-08-09 13:58:02 +06:00
TopoDS_Shape& theApplyedWire,
2012-10-08 17:16:36 +06:00
TopoDS_Shape& theLastSegment)
2009-02-13 17:16:39 +05:00
{
2012-08-09 13:58:02 +06:00
QList<gp_Pnt> points;
2012-10-08 17:16:36 +06:00
foreach (XYZ xyz, myPointsList) {
2012-08-09 13:58:02 +06:00
gp_Pnt p(xyz.x, xyz.y, xyz.z);
2012-10-08 17:16:36 +06:00
if (points.isEmpty() || points.last().Distance(p) > gp::Resolution())
2012-08-09 13:58:02 +06:00
points << p;
2012-10-08 17:16:36 +06:00
}
if (points.count() == 1) {
2012-08-09 13:58:02 +06:00
// only one point is created
BRepBuilderAPI_MakeVertex mkVertex (points.last());
theApplyedWire = mkVertex.Shape();
}
2012-10-08 17:16:36 +06:00
else if (points.count() > 1) {
2012-08-09 13:58:02 +06:00
// wire is created
BRepBuilderAPI_MakePolygon mkWire;
2012-10-08 17:16:36 +06:00
foreach(gp_Pnt p, points)
2012-08-09 13:58:02 +06:00
mkWire.Add(p);
theApplyedWire = mkWire.Shape();
}
XYZ curxyz = getCurrentPoint();
gp_Pnt curpnt(curxyz.x, curxyz.y, curxyz.z);
2012-10-08 17:16:36 +06:00
if (points.isEmpty() || points.last().Distance(curpnt) <= gp::Resolution()) {
2012-08-09 13:58:02 +06:00
BRepBuilderAPI_MakeVertex mkVertex (curpnt);
theLastSegment = mkVertex.Shape();
}
else {
BRepBuilderAPI_MakeEdge mkEdge(points.last(), curpnt);
theLastSegment = mkEdge.Shape();
}
/* VSR: old algorithm does not work properly, see bug 0020899
2009-02-13 17:16:39 +05:00
TopoDS_Shape aShape;
2012-10-08 17:16:36 +06:00
if (!GEOMBase::GetShape(theObject, aShape))
2012-08-09 13:58:02 +06:00
return false;
2012-10-08 17:16:36 +06:00
if (aShape.ShapeType() != TopAbs_WIRE && aShape.ShapeType() != TopAbs_VERTEX)
2009-02-13 17:16:39 +05:00
return false;
2012-08-09 13:58:02 +06:00
theApplyedWire = aShape;
2012-10-08 17:16:36 +06:00
if (myOK)
2009-02-13 17:16:39 +05:00
return true;
BRepBuilderAPI_MakeWire aBuilder;
2012-10-08 17:16:36 +06:00
TopExp_Explorer edgeExp(aShape, TopAbs_EDGE);
while (1) {
2012-08-09 13:58:02 +06:00
TopoDS_Shape anEdge = edgeExp.Current();
edgeExp.Next();
2012-10-08 17:16:36 +06:00
if (edgeExp.More()) // i.e. non-last edge
aBuilder.Add(TopoDS::Edge(anEdge));
2009-02-13 17:16:39 +05:00
else {
theLastSegment = anEdge;
break;
}
}
2012-10-08 17:16:36 +06:00
if (aBuilder.IsDone()) {
2009-02-13 17:16:39 +05:00
theApplyedWire = aBuilder.Shape();
2012-08-09 13:58:02 +06:00
}
2012-10-08 17:16:36 +06:00
else if (!theLastSegment.IsNull()) {
TopExp_Explorer vertexExp(theLastSegment, TopAbs_VERTEX);
2012-08-09 13:58:02 +06:00
theApplyedWire = vertexExp.Current();
}
*/
2009-02-13 17:16:39 +05:00
return true;
}
2012-08-09 13:58:02 +06:00
//================================================================
// Function : doubleToString
// Purpose : converts double to string
//================================================================
2012-10-08 17:16:36 +06:00
std::string EntityGUI_3DSketcherDlg::doubleToString (double num)
2012-08-09 13:58:02 +06:00
{
// truncate num
int digNum = 5;
char format = 'g'; // truncated to a number of significant digits
2012-10-08 17:16:36 +06:00
return QString::number(num, format, digNum).toStdString();
2012-08-09 13:58:02 +06:00
}