|
|
|
|
@@ -47,7 +47,7 @@
|
|
|
|
|
#include <Gui/Command.h>
|
|
|
|
|
#include <Gui/View3DInventor.h>
|
|
|
|
|
#include <Gui/View3DInventorViewer.h>
|
|
|
|
|
#include <Gui/TaskView/TaskView.h>
|
|
|
|
|
#include <Gui/TaskView/TaskView.h>
|
|
|
|
|
#include <Mod/Part/App/Tools.h>
|
|
|
|
|
|
|
|
|
|
#include "DlgPrimitives.h"
|
|
|
|
|
@@ -55,43 +55,43 @@
|
|
|
|
|
using namespace PartGui;
|
|
|
|
|
|
|
|
|
|
namespace PartGui {
|
|
|
|
|
|
|
|
|
|
const char* gce_ErrorStatusText(gce_ErrorType et)
|
|
|
|
|
{
|
|
|
|
|
switch (et)
|
|
|
|
|
{
|
|
|
|
|
case gce_Done:
|
|
|
|
|
return "Construction was successful";
|
|
|
|
|
case gce_ConfusedPoints:
|
|
|
|
|
return "Two points are coincident";
|
|
|
|
|
case gce_NegativeRadius:
|
|
|
|
|
return "Radius value is negative";
|
|
|
|
|
case gce_ColinearPoints:
|
|
|
|
|
return "Three points are collinear";
|
|
|
|
|
case gce_IntersectionError:
|
|
|
|
|
return "Intersection cannot be computed";
|
|
|
|
|
case gce_NullAxis:
|
|
|
|
|
return "Axis is undefined";
|
|
|
|
|
case gce_NullAngle:
|
|
|
|
|
return "Angle value is invalid (usually null)";
|
|
|
|
|
case gce_NullRadius:
|
|
|
|
|
return "Radius is null";
|
|
|
|
|
case gce_InvertAxis:
|
|
|
|
|
return "Axis value is invalid";
|
|
|
|
|
case gce_BadAngle:
|
|
|
|
|
return "Angle value is invalid";
|
|
|
|
|
case gce_InvertRadius:
|
|
|
|
|
return "Radius value is incorrect (usually with respect to another radius)";
|
|
|
|
|
case gce_NullFocusLength:
|
|
|
|
|
return "Focal distance is null";
|
|
|
|
|
case gce_NullVector:
|
|
|
|
|
return "Vector is null";
|
|
|
|
|
case gce_BadEquation:
|
|
|
|
|
return "Coefficients are incorrect (applies to the equation of a geometric object)";
|
|
|
|
|
default:
|
|
|
|
|
return "Creation of geometry failed";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const char* gce_ErrorStatusText(gce_ErrorType et)
|
|
|
|
|
{
|
|
|
|
|
switch (et)
|
|
|
|
|
{
|
|
|
|
|
case gce_Done:
|
|
|
|
|
return "Construction was successful";
|
|
|
|
|
case gce_ConfusedPoints:
|
|
|
|
|
return "Two points are coincident";
|
|
|
|
|
case gce_NegativeRadius:
|
|
|
|
|
return "Radius value is negative";
|
|
|
|
|
case gce_ColinearPoints:
|
|
|
|
|
return "Three points are collinear";
|
|
|
|
|
case gce_IntersectionError:
|
|
|
|
|
return "Intersection cannot be computed";
|
|
|
|
|
case gce_NullAxis:
|
|
|
|
|
return "Axis is undefined";
|
|
|
|
|
case gce_NullAngle:
|
|
|
|
|
return "Angle value is invalid (usually null)";
|
|
|
|
|
case gce_NullRadius:
|
|
|
|
|
return "Radius is null";
|
|
|
|
|
case gce_InvertAxis:
|
|
|
|
|
return "Axis value is invalid";
|
|
|
|
|
case gce_BadAngle:
|
|
|
|
|
return "Angle value is invalid";
|
|
|
|
|
case gce_InvertRadius:
|
|
|
|
|
return "Radius value is incorrect (usually with respect to another radius)";
|
|
|
|
|
case gce_NullFocusLength:
|
|
|
|
|
return "Focal distance is null";
|
|
|
|
|
case gce_NullVector:
|
|
|
|
|
return "Vector is null";
|
|
|
|
|
case gce_BadEquation:
|
|
|
|
|
return "Coefficients are incorrect (applies to the equation of a geometric object)";
|
|
|
|
|
default:
|
|
|
|
|
return "Creation of geometry failed";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Picker::createPrimitive(QWidget* widget, const QString& descr, Gui::Document* doc)
|
|
|
|
|
{
|
|
|
|
|
@@ -113,17 +113,17 @@ void Picker::createPrimitive(QWidget* widget, const QString& descr, Gui::Documen
|
|
|
|
|
|
|
|
|
|
QString Picker::toPlacement(const gp_Ax2& axis) const
|
|
|
|
|
{
|
|
|
|
|
gp_Dir dir = axis.Direction();
|
|
|
|
|
gp_Pnt pnt = gp_Pnt(0.0,0.0,0.0);
|
|
|
|
|
gp_Ax3 ax3(pnt, dir, axis.XDirection());
|
|
|
|
|
|
|
|
|
|
gp_Trsf Trf;
|
|
|
|
|
Trf.SetTransformation(ax3);
|
|
|
|
|
Trf.Invert();
|
|
|
|
|
|
|
|
|
|
gp_XYZ theAxis(0,0,1);
|
|
|
|
|
Standard_Real theAngle = 0.0;
|
|
|
|
|
Trf.GetRotation(theAxis,theAngle);
|
|
|
|
|
gp_Dir dir = axis.Direction();
|
|
|
|
|
gp_Pnt pnt = gp_Pnt(0.0,0.0,0.0);
|
|
|
|
|
gp_Ax3 ax3(pnt, dir, axis.XDirection());
|
|
|
|
|
|
|
|
|
|
gp_Trsf Trf;
|
|
|
|
|
Trf.SetTransformation(ax3);
|
|
|
|
|
Trf.Invert();
|
|
|
|
|
|
|
|
|
|
gp_XYZ theAxis(0,0,1);
|
|
|
|
|
Standard_Real theAngle = 0.0;
|
|
|
|
|
Trf.GetRotation(theAxis,theAngle);
|
|
|
|
|
|
|
|
|
|
Base::Rotation rot(Base::convertTo<Base::Vector3d>(theAxis), theAngle);
|
|
|
|
|
gp_Pnt loc = axis.Location();
|
|
|
|
|
@@ -153,10 +153,10 @@ public:
|
|
|
|
|
QString command(App::Document* doc) const
|
|
|
|
|
{
|
|
|
|
|
GC_MakeArcOfCircle arc(points[0], points[1], points[2]);
|
|
|
|
|
if (!arc.IsDone())
|
|
|
|
|
throw Base::Exception(gce_ErrorStatusText(arc.Status()));
|
|
|
|
|
Handle_Geom_TrimmedCurve trim = arc.Value();
|
|
|
|
|
Handle_Geom_Circle circle = Handle_Geom_Circle::DownCast(trim->BasisCurve());
|
|
|
|
|
if (!arc.IsDone())
|
|
|
|
|
throw Base::Exception(gce_ErrorStatusText(arc.Status()));
|
|
|
|
|
Handle_Geom_TrimmedCurve trim = arc.Value();
|
|
|
|
|
Handle_Geom_Circle circle = Handle_Geom_Circle::DownCast(trim->BasisCurve());
|
|
|
|
|
|
|
|
|
|
QString name = QString::fromAscii(doc->getUniqueObjectName("Circle").c_str());
|
|
|
|
|
return QString::fromAscii(
|
|
|
|
|
@@ -270,7 +270,6 @@ DlgPrimitives::~DlgPrimitives()
|
|
|
|
|
void DlgPrimitives::pickCallback(void * ud, SoEventCallback * n)
|
|
|
|
|
{
|
|
|
|
|
const SoMouseButtonEvent * mbe = static_cast<const SoMouseButtonEvent*>(n->getEvent());
|
|
|
|
|
Gui::View3DInventorViewer* view = reinterpret_cast<Gui::View3DInventorViewer*>(n->getUserData());
|
|
|
|
|
|
|
|
|
|
// Mark all incoming mouse button events as handled, especially, to deactivate the selection node
|
|
|
|
|
n->setHandled();
|
|
|
|
|
@@ -569,18 +568,18 @@ void DlgPrimitives::createPrimitive(const QString& placement)
|
|
|
|
|
.arg(ui.comboBox1->currentText()), QString::fromLatin1(e.what()));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ----------------------------------------------
|
|
|
|
|
|
|
|
|
|
/* TRANSLATOR PartGui::Location */
|
|
|
|
|
|
|
|
|
|
Location::Location(QWidget* parent)
|
|
|
|
|
{
|
|
|
|
|
ui.setupUi(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Location::~Location()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
// ----------------------------------------------
|
|
|
|
|
|
|
|
|
|
/* TRANSLATOR PartGui::Location */
|
|
|
|
|
|
|
|
|
|
Location::Location(QWidget* parent)
|
|
|
|
|
{
|
|
|
|
|
ui.setupUi(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Location::~Location()
|
|
|
|
|
{
|
|
|
|
|
// no need to delete child widgets, Qt does it all for us
|
|
|
|
|
if (!this->activeView.isNull()) {
|
|
|
|
|
Gui::View3DInventorViewer* viewer = static_cast<Gui::View3DInventor*>
|
|
|
|
|
@@ -589,7 +588,7 @@ Location::~Location()
|
|
|
|
|
viewer->setRedirectToSceneGraph(false);
|
|
|
|
|
viewer->removeEventCallback(SoMouseButtonEvent::getClassTypeId(), pickCallback,this);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Location::on_viewPositionButton_clicked()
|
|
|
|
|
{
|
|
|
|
|
@@ -643,46 +642,46 @@ void Location::pickCallback(void * ud, SoEventCallback * n)
|
|
|
|
|
QString Location::toPlacement() const
|
|
|
|
|
{
|
|
|
|
|
Base::Vector3f d = ui.loc->getDirection();
|
|
|
|
|
gp_Dir dir = gp_Dir(d.x,d.y,d.z);
|
|
|
|
|
gp_Pnt pnt = gp_Pnt(0.0,0.0,0.0);
|
|
|
|
|
gp_Ax3 ax3;
|
|
|
|
|
|
|
|
|
|
double cosNX = dir.Dot(gp::DX());
|
|
|
|
|
double cosNY = dir.Dot(gp::DY());
|
|
|
|
|
double cosNZ = dir.Dot(gp::DZ());
|
|
|
|
|
std::vector<double> cosXYZ;
|
|
|
|
|
cosXYZ.push_back(fabs(cosNX));
|
|
|
|
|
cosXYZ.push_back(fabs(cosNY));
|
|
|
|
|
cosXYZ.push_back(fabs(cosNZ));
|
|
|
|
|
|
|
|
|
|
int pos = std::max_element(cosXYZ.begin(), cosXYZ.end()) - cosXYZ.begin();
|
|
|
|
|
|
|
|
|
|
// +X/-X
|
|
|
|
|
if (pos == 0) {
|
|
|
|
|
if (cosNX > 0)
|
|
|
|
|
ax3 = gp_Ax3(pnt, dir, gp_Dir(0,1,0));
|
|
|
|
|
else
|
|
|
|
|
ax3 = gp_Ax3(pnt, dir, gp_Dir(0,-1,0));
|
|
|
|
|
}
|
|
|
|
|
// +Y/-Y
|
|
|
|
|
else if (pos == 1) {
|
|
|
|
|
if (cosNY > 0)
|
|
|
|
|
ax3 = gp_Ax3(pnt, dir, gp_Dir(0,0,1));
|
|
|
|
|
else
|
|
|
|
|
ax3 = gp_Ax3(pnt, dir, gp_Dir(0,0,-1));
|
|
|
|
|
}
|
|
|
|
|
// +Z/-Z
|
|
|
|
|
else {
|
|
|
|
|
ax3 = gp_Ax3(pnt, dir, gp_Dir(1,0,0));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gp_Trsf Trf;
|
|
|
|
|
Trf.SetTransformation(ax3);
|
|
|
|
|
Trf.Invert();
|
|
|
|
|
|
|
|
|
|
gp_XYZ theAxis(0,0,1);
|
|
|
|
|
Standard_Real theAngle = 0.0;
|
|
|
|
|
Trf.GetRotation(theAxis,theAngle);
|
|
|
|
|
gp_Dir dir = gp_Dir(d.x,d.y,d.z);
|
|
|
|
|
gp_Pnt pnt = gp_Pnt(0.0,0.0,0.0);
|
|
|
|
|
gp_Ax3 ax3;
|
|
|
|
|
|
|
|
|
|
double cosNX = dir.Dot(gp::DX());
|
|
|
|
|
double cosNY = dir.Dot(gp::DY());
|
|
|
|
|
double cosNZ = dir.Dot(gp::DZ());
|
|
|
|
|
std::vector<double> cosXYZ;
|
|
|
|
|
cosXYZ.push_back(fabs(cosNX));
|
|
|
|
|
cosXYZ.push_back(fabs(cosNY));
|
|
|
|
|
cosXYZ.push_back(fabs(cosNZ));
|
|
|
|
|
|
|
|
|
|
int pos = std::max_element(cosXYZ.begin(), cosXYZ.end()) - cosXYZ.begin();
|
|
|
|
|
|
|
|
|
|
// +X/-X
|
|
|
|
|
if (pos == 0) {
|
|
|
|
|
if (cosNX > 0)
|
|
|
|
|
ax3 = gp_Ax3(pnt, dir, gp_Dir(0,1,0));
|
|
|
|
|
else
|
|
|
|
|
ax3 = gp_Ax3(pnt, dir, gp_Dir(0,-1,0));
|
|
|
|
|
}
|
|
|
|
|
// +Y/-Y
|
|
|
|
|
else if (pos == 1) {
|
|
|
|
|
if (cosNY > 0)
|
|
|
|
|
ax3 = gp_Ax3(pnt, dir, gp_Dir(0,0,1));
|
|
|
|
|
else
|
|
|
|
|
ax3 = gp_Ax3(pnt, dir, gp_Dir(0,0,-1));
|
|
|
|
|
}
|
|
|
|
|
// +Z/-Z
|
|
|
|
|
else {
|
|
|
|
|
ax3 = gp_Ax3(pnt, dir, gp_Dir(1,0,0));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gp_Trsf Trf;
|
|
|
|
|
Trf.SetTransformation(ax3);
|
|
|
|
|
Trf.Invert();
|
|
|
|
|
|
|
|
|
|
gp_XYZ theAxis(0,0,1);
|
|
|
|
|
Standard_Real theAngle = 0.0;
|
|
|
|
|
Trf.GetRotation(theAxis,theAngle);
|
|
|
|
|
|
|
|
|
|
Base::Rotation rot(Base::convertTo<Base::Vector3d>(theAxis), theAngle);
|
|
|
|
|
Base::Vector3f loc = ui.loc->getPosition();
|
|
|
|
|
@@ -696,52 +695,52 @@ QString Location::toPlacement() const
|
|
|
|
|
.arg(rot[2],0,'f',2)
|
|
|
|
|
.arg(rot[3],0,'f',2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ----------------------------------------------
|
|
|
|
|
|
|
|
|
|
/* TRANSLATOR PartGui::TaskPrimitives */
|
|
|
|
|
|
|
|
|
|
TaskPrimitives::TaskPrimitives()
|
|
|
|
|
{
|
|
|
|
|
Gui::TaskView::TaskBox* taskbox;
|
|
|
|
|
widget = new DlgPrimitives();
|
|
|
|
|
taskbox = new Gui::TaskView::TaskBox(QPixmap(), widget->windowTitle(),true, 0);
|
|
|
|
|
taskbox->groupLayout()->addWidget(widget);
|
|
|
|
|
Content.push_back(taskbox);
|
|
|
|
|
|
|
|
|
|
location = new Location();
|
|
|
|
|
taskbox = new Gui::TaskView::TaskBox(QPixmap(), location->windowTitle(),true, 0);
|
|
|
|
|
taskbox->groupLayout()->addWidget(location);
|
|
|
|
|
taskbox->hideGroupBox();
|
|
|
|
|
Content.push_back(taskbox);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TaskPrimitives::~TaskPrimitives()
|
|
|
|
|
{
|
|
|
|
|
// automatically deleted in the sub-class
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QDialogButtonBox::StandardButtons TaskPrimitives::getStandardButtons() const
|
|
|
|
|
{
|
|
|
|
|
return QDialogButtonBox::Close|
|
|
|
|
|
QDialogButtonBox::Ok;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ----------------------------------------------
|
|
|
|
|
|
|
|
|
|
/* TRANSLATOR PartGui::TaskPrimitives */
|
|
|
|
|
|
|
|
|
|
TaskPrimitives::TaskPrimitives()
|
|
|
|
|
{
|
|
|
|
|
Gui::TaskView::TaskBox* taskbox;
|
|
|
|
|
widget = new DlgPrimitives();
|
|
|
|
|
taskbox = new Gui::TaskView::TaskBox(QPixmap(), widget->windowTitle(),true, 0);
|
|
|
|
|
taskbox->groupLayout()->addWidget(widget);
|
|
|
|
|
Content.push_back(taskbox);
|
|
|
|
|
|
|
|
|
|
location = new Location();
|
|
|
|
|
taskbox = new Gui::TaskView::TaskBox(QPixmap(), location->windowTitle(),true, 0);
|
|
|
|
|
taskbox->groupLayout()->addWidget(location);
|
|
|
|
|
taskbox->hideGroupBox();
|
|
|
|
|
Content.push_back(taskbox);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TaskPrimitives::~TaskPrimitives()
|
|
|
|
|
{
|
|
|
|
|
// automatically deleted in the sub-class
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QDialogButtonBox::StandardButtons TaskPrimitives::getStandardButtons() const
|
|
|
|
|
{
|
|
|
|
|
return QDialogButtonBox::Close|
|
|
|
|
|
QDialogButtonBox::Ok;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TaskPrimitives::modifyStandardButtons(QDialogButtonBox* box)
|
|
|
|
|
{
|
|
|
|
|
QPushButton* btn = box->button(QDialogButtonBox::Ok);
|
|
|
|
|
btn->setText(QApplication::translate("PartGui::DlgPrimitives", "&Create"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TaskPrimitives::accept()
|
|
|
|
|
{
|
|
|
|
|
widget->createPrimitive(location->toPlacement());
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TaskPrimitives::reject()
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TaskPrimitives::accept()
|
|
|
|
|
{
|
|
|
|
|
widget->createPrimitive(location->toPlacement());
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TaskPrimitives::reject()
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#include "moc_DlgPrimitives.cpp"
|
|
|
|
|
|