allow origin lines in datum features

This commit is contained in:
Stefan Tröger 2015-05-06 19:44:20 +02:00
parent 63015c769e
commit 4c29efea1f
7 changed files with 125 additions and 13 deletions

View File

@ -125,6 +125,24 @@ bool ViewProviderOrigin::isTemporaryVisibilityMode()
return tempVisMode;
}
void ViewProviderOrigin::setTemporaryVisibilityAxis(bool onoff)
{
for(App::DocumentObject* obj : static_cast<App::Origin*>(pcObject)->getObjectsOfType(App::Plane::getClassTypeId())) {
Gui::ViewProvider* vp = tempVisDoc->getViewProvider(obj);
vp->setVisible(onoff);
}
}
void ViewProviderOrigin::setTemporaryVisibilityPlanes(bool onoff)
{
for(App::DocumentObject* obj : static_cast<App::Origin*>(pcObject)->getObjectsOfType(App::Line::getClassTypeId())) {
Gui::ViewProvider* vp = tempVisDoc->getViewProvider(obj);
vp->setVisible(onoff);
}
}
// Python feature -----------------------------------------------------------------------

View File

@ -54,6 +54,8 @@ public:
//temporary mode to override visibility of grouped objects
void setTemporaryVisibilityMode(bool onoff, Gui::Document* doc = NULL);
bool isTemporaryVisibilityMode();
void setTemporaryVisibilityAxis(bool onoff);
void setTemporaryVisibilityPlanes(bool onoff);
void setTemporaryVisibility(App::DocumentObject* obj, bool onoff);
private:

View File

@ -62,6 +62,8 @@
#include <QObject>
#include <App/Plane.h>
#include <App/Part.h>
#include <App/Line.h>
#include "DatumPoint.h"
#include "DatumLine.h"
#include "DatumPlane.h"
@ -207,7 +209,38 @@ void Line::onChanged(const App::Property *prop)
s3 = new Geom_Plane(base, normal);
}
}
} else if (refs[i]->getTypeId().isDerivedFrom(PartDesign::Plane::getClassTypeId())) {
} else if (refs[i]->getTypeId().isDerivedFrom(App::Line::getClassTypeId())) {
App::Line* l = static_cast<App::Line*>(refs[i]);
gp_Dir ldir;
if (strcmp(l->getNameInDocument(), App::Part::BaselineTypes[0]) == 0)
ldir = gp_Dir(1,0,0);
else if (strcmp(l->getNameInDocument(), App::Part::BaselineTypes[1]) == 0)
ldir = gp_Dir(0,1,0);
else if (strcmp(l->getNameInDocument(), App::Part::BaselineTypes[2]) == 0)
ldir = gp_Dir(0,0,1);
if (s1.IsNull()) {
base = new Base::Vector3d (0,0,0);
direction = new Base::Vector3d (ldir.X(), ldir.Y(), ldir.Z());
} else {
// Create plane through line normal to s1
Handle_Geom_Plane pl = Handle_Geom_Plane::DownCast(s1);
if (pl.IsNull())
return; // Non-planar first surface
gp_Dir normal = ldir.Crossed(pl->Axis().Direction());
double offset1 = Offset.getValue();
double offset2 = Offset2.getValue();
gp_Pnt base = gp_Pnt(0,0,0);
if (s2.IsNull()) {
base.Translate(offset1 * normal);
s2 = new Geom_Plane(base, normal);
} else {
base.Translate(offset2 * normal);
s3 = new Geom_Plane(base, normal);
}
}
}else if (refs[i]->getTypeId().isDerivedFrom(PartDesign::Plane::getClassTypeId())) {
PartDesign::Plane* p = static_cast<PartDesign::Plane*>(refs[i]);
Base::Vector3d base = p->getBasePoint();
Base::Vector3d normal = p->getNormal();
@ -226,11 +259,11 @@ void Line::onChanged(const App::Property *prop)
// Note: We only handle the three base planes here
gp_Pnt base(0,0,0);
gp_Dir normal;
if (strcmp(p->getNameInDocument(), "BaseplaneXY") == 0)
if (strcmp(p->getNameInDocument(), App::Part::BaseplaneTypes[0]) == 0)
normal = gp_Dir(0,0,1);
else if (strcmp(p->getNameInDocument(), "BaseplaneYZ") == 0)
else if (strcmp(p->getNameInDocument(), App::Part::BaseplaneTypes[2]) == 0)
normal = gp_Dir(1,0,0);
else if (strcmp(p->getNameInDocument(), "BaseplaneXZ") == 0)
else if (strcmp(p->getNameInDocument(), App::Part::BaseplaneTypes[1]) == 0)
normal = gp_Dir(0,1,0);
double offset1 = Offset.getValue();

View File

@ -60,6 +60,8 @@
#include <QObject>
#include <App/Plane.h>
#include <App/Part.h>
#include <App/Line.h>
#include "DatumPoint.h"
#include "DatumLine.h"
#include "DatumPlane.h"
@ -220,6 +222,17 @@ void Plane::onChanged(const App::Property *prop)
Base::Vector3d base = l->getBasePoint();
Base::Vector3d dir = l->getDirection();
line = new gp_Lin(gp_Pnt(base.x, base.y, base.z), gp_Dir(dir.x, dir.y, dir.z));
} else if (refs[i]->getTypeId().isDerivedFrom(App::Line::getClassTypeId())) {
App::Line* l = static_cast<App::Line*>(refs[i]);
Base::Vector3d base = Base::Vector3d(0,0,0);
gp_Dir dir;
if (strcmp(l->getNameInDocument(), App::Part::BaselineTypes[0]) == 0)
dir = gp_Dir(1,0,0);
else if (strcmp(l->getNameInDocument(), App::Part::BaselineTypes[1]) == 0)
dir = gp_Dir(0,1,0);
else if (strcmp(l->getNameInDocument(), App::Part::BaselineTypes[2]) == 0)
dir = gp_Dir(0,0,1);
line = new gp_Lin(gp_Pnt(base.x, base.y, base.z), gp_Dir(dir.X(), dir.Y(), dir.Z()));
} else if (refs[i]->getTypeId().isDerivedFrom(PartDesign::Plane::getClassTypeId())) {
PartDesign::Plane* p = static_cast<PartDesign::Plane*>(refs[i]);
p1 = new Base::Vector3d(p->getBasePoint());
@ -229,11 +242,11 @@ void Plane::onChanged(const App::Property *prop)
// Note: We only handle the three base planes here
p1 = new Base::Vector3d(0,0,0);
normal = new Base::Vector3d;
if (strcmp(p->getNameInDocument(), "BaseplaneXY") == 0)
if (strcmp(p->getNameInDocument(), App::Part::BaseplaneTypes[0]) == 0)
*normal = Base::Vector3d(0,0,1);
else if (strcmp(p->getNameInDocument(), "BaseplaneXZ") == 0)
else if (strcmp(p->getNameInDocument(), App::Part::BaseplaneTypes[2]) == 0)
*normal = Base::Vector3d(0,1,0);
else if (strcmp(p->getNameInDocument(), "BaseplaneYZ") == 0)
else if (strcmp(p->getNameInDocument(), App::Part::BaseplaneTypes[1]) == 0)
*normal = Base::Vector3d(1,0,0);
} else if (refs[i]->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId())) {
Part::Feature* feature = static_cast<Part::Feature*>(refs[i]);

View File

@ -60,6 +60,8 @@
#include <QObject>
#include <App/Plane.h>
#include <App/Line.h>
#include <App/Part.h>
#include "DatumPoint.h"
#include "DatumLine.h"
#include "DatumPlane.h"
@ -197,16 +199,34 @@ void Point::onChanged(const App::Property* prop)
s2 = new Geom_Plane(gp_Pnt(base.x, base.y, base.z), gp_Dir(normal.x, normal.y, normal.z));
else
s3 = new Geom_Plane(gp_Pnt(base.x, base.y, base.z), gp_Dir(normal.x, normal.y, normal.z));
} else if (refs[i]->getTypeId().isDerivedFrom(App::Line::getClassTypeId())) {
App::Line* l = static_cast<App::Line*>(refs[i]);
// Note: We only handle the three base planes here
gp_Pnt base(0,0,0);
gp_Dir normal;
if (strcmp(l->getNameInDocument(), App::Part::BaselineTypes[0]) == 0)
normal = gp_Dir(1,0,0);
else if (strcmp(l->getNameInDocument(), App::Part::BaselineTypes[1]) == 0)
normal = gp_Dir(0,1,0);
else if (strcmp(l->getNameInDocument(), App::Part::BaselineTypes[2]) == 0)
normal = gp_Dir(0,0,1);
if (s1.IsNull())
c1 = new Geom_Line(base, normal);
else if (s2.IsNull())
c2 = new Geom_Line(base, normal);
} else if (refs[i]->getTypeId().isDerivedFrom(App::Plane::getClassTypeId())) {
App::Plane* p = static_cast<App::Plane*>(refs[i]);
// Note: We only handle the three base planes here
gp_Pnt base(0,0,0);
gp_Dir normal;
if (strcmp(p->getNameInDocument(), "BaseplaneXY") == 0)
if (strcmp(p->getNameInDocument(), App::Part::BaseplaneTypes[0]) == 0)
normal = gp_Dir(0,0,1);
else if (strcmp(p->getNameInDocument(), "BaseplaneYZ") == 0)
else if (strcmp(p->getNameInDocument(), App::Part::BaseplaneTypes[2]) == 0)
normal = gp_Dir(1,0,0);
else if (strcmp(p->getNameInDocument(), "BaseplaneXZ") == 0)
else if (strcmp(p->getNameInDocument(), App::Part::BaseplaneTypes[1]) == 0)
normal = gp_Dir(0,1,0);
if (s1.IsNull())
@ -391,7 +411,7 @@ const QString getRefType(const App::DocumentObject* obj, const std::string& subn
if ((type == App::Plane::getClassTypeId()) || (type == PartDesign::Plane::getClassTypeId()))
return PLANE;
else if (type == PartDesign::Line::getClassTypeId())
else if ((type == App::Line::getClassTypeId()) || (type == PartDesign::Line::getClassTypeId()))
return LINE;
else if (type == PartDesign::Point::getClassTypeId())
return POINT;

View File

@ -32,6 +32,7 @@
#include <App/Plane.h>
#include <App/Part.h>
#include <App/Line.h>
#include <Gui/Application.h>
#include <Gui/Document.h>
#include <Mod/Part/App/TopoShape.h>
@ -61,6 +62,9 @@ bool ReferenceSelection::allow(App::Document* pDoc, App::DocumentObject* pObj, c
if (plane && (pObj->getTypeId().isDerivedFrom(App::Plane::getClassTypeId())))
// Note: It is assumed that a Part has exactly 3 App::Plane objects at the root of the feature tree
return true;
if (edge && (pObj->getTypeId().isDerivedFrom(App::Line::getClassTypeId())))
return true;
if (pObj->getTypeId().isDerivedFrom(Part::Datum::getClassTypeId())) {
// Allow selecting Part::Datum features from the active Body

View File

@ -36,6 +36,7 @@
#include <App/Application.h>
#include <App/Document.h>
#include <App/Plane.h>
#include <App/Line.h>
#include <Gui/Application.h>
#include <Gui/Document.h>
#include <Gui/BitmapFactory.h>
@ -44,6 +45,7 @@
#include <Base/Console.h>
#include <Gui/Selection.h>
#include <Gui/Command.h>
#include <Gui/ViewProviderOrigin.h>
#include <Mod/Part/App/PrimitiveFeature.h>
#include <Mod/Part/App/DatumFeature.h>
#include <Mod/PartDesign/App/Body.h>
@ -62,8 +64,9 @@ const QString makeRefString(const App::DocumentObject* obj, const std::string& s
return QObject::tr("No reference selected");
if (obj->getTypeId().isDerivedFrom(App::Plane::getClassTypeId()) ||
obj->getTypeId().isDerivedFrom(App::Line::getClassTypeId()) ||
obj->getTypeId().isDerivedFrom(Part::Datum::getClassTypeId()))
// App::Plane or Datum feature
// App::Plane, Liine or Datum feature
return QString::fromAscii(obj->getNameInDocument());
if ((sub.size() > 4) && (sub.substr(0,4) == "Face")) {
@ -183,6 +186,15 @@ TaskDatumParameters::TaskDatumParameters(ViewProviderDatum *DatumView,QWidget *p
ui->buttonRef3->blockSignals(false);
ui->lineRef3->blockSignals(false);
updateUI();
//temporary show all coordinate systems for selection
for(auto origin : Gui::Application::Instance->activeDocument()->getViewProvidersOfType(Gui::ViewProviderOrigin::getClassTypeId())) {
static_cast<Gui::ViewProviderOrigin*>(origin)->setTemporaryVisibilityMode(true, Gui::Application::Instance->activeDocument());
static_cast<Gui::ViewProviderOrigin*>(origin)->setTemporaryVisibilityAxis(true);
static_cast<Gui::ViewProviderOrigin*>(origin)->setTemporaryVisibilityPlanes(true);
}
}
const QString makeRefText(std::set<QString> hint)
@ -363,6 +375,7 @@ void TaskDatumParameters::onSelectionChanged(const Gui::SelectionChanges& msg)
// Remove subname for planes and datum features
if (selObj->getTypeId().isDerivedFrom(App::Plane::getClassTypeId()) ||
selObj->getTypeId().isDerivedFrom(App::Line::getClassTypeId()) ||
selObj->getTypeId().isDerivedFrom(Part::Datum::getClassTypeId()))
subname = "";
@ -512,8 +525,11 @@ void TaskDatumParameters::onRefName(const QString& text, const int idx)
if (obj->getTypeId().isDerivedFrom(App::Plane::getClassTypeId())) {
// everything is OK (we assume a Part can only have exactly 3 App::Plane objects located at the base of the feature tree)
subElement = "";
} else if (obj->getTypeId().isDerivedFrom(App::Line::getClassTypeId())) {
// everything is OK (we assume a Part can only have exactly 3 App::Line objects located at the base of the feature tree)
subElement = "";
} else if (obj->getTypeId().isDerivedFrom(Part::Datum::getClassTypeId())) {
if (!activeBody->hasFeature(obj))
if (!activeBody->hasFeature(obj))
return;
subElement = "";
} else {
@ -625,6 +641,12 @@ QString TaskDatumParameters::getReference(const int idx) const
TaskDatumParameters::~TaskDatumParameters()
{
//end temporary view mode of all coordinate systems
for(auto origin : Gui::Application::Instance->activeDocument()->getViewProvidersOfType(Gui::ViewProviderOrigin::getClassTypeId())) {
static_cast<Gui::ViewProviderOrigin*>(origin)->setTemporaryVisibilityMode(false);
}
delete ui;
}