Gui/ViewProciderPart: fix XZ plane orientation
Also fix spacing and a Workbench.getValue() condition
This commit is contained in:
parent
ca8be01a4b
commit
06139ee8f3
|
@ -60,7 +60,7 @@ PROPERTY_SOURCE(Gui::ViewProviderPart, Gui::ViewProviderGeometryObject)
|
|||
/**
|
||||
* Creates the view provider for an object group.
|
||||
*/
|
||||
ViewProviderPart::ViewProviderPart()
|
||||
ViewProviderPart::ViewProviderPart()
|
||||
{
|
||||
ADD_PROPERTY(Workbench,("PartDesignWorkbench"));
|
||||
}
|
||||
|
@ -93,71 +93,71 @@ void ViewProviderPart::updateData(const App::Property* prop)
|
|||
void ViewProviderPart::onObjectChanged(const App::DocumentObject& obj, const App::Property&)
|
||||
{
|
||||
App::Part* part = static_cast<App::Part*>(pcObject);
|
||||
if(static_cast<App::Part*>(pcObject)->hasObject(&obj) &&
|
||||
if(static_cast<App::Part*>(pcObject)->hasObject(&obj) &&
|
||||
obj.getTypeId() != App::Origin::getClassTypeId() &&
|
||||
obj.getTypeId() != App::Plane::getClassTypeId() &&
|
||||
obj.getTypeId() != App::Line::getClassTypeId()) {
|
||||
|
||||
|
||||
View3DInventorViewer* viewer = static_cast<View3DInventor*>(this->getActiveView())->getViewer();
|
||||
SoGetBoundingBoxAction bboxAction(viewer->getSoRenderManager()->getViewportRegion());
|
||||
|
||||
|
||||
//calculate for everything but datums
|
||||
SbBox3f bbox(1e-9, 1e-9, 1e-9, 1e-9, 1e-9, 1e-9);
|
||||
for(App::DocumentObject* obj : part->getObjects()) {
|
||||
if(obj->getTypeId() != App::Origin::getClassTypeId() &&
|
||||
obj->getTypeId() != App::Plane::getClassTypeId() &&
|
||||
obj->getTypeId() != App::Plane::getClassTypeId() &&
|
||||
obj->getTypeId() != App::Line::getClassTypeId() ) {
|
||||
|
||||
//getting crash on deletion PartDesign::Body object. no viewprovider.
|
||||
ViewProvider *viewProvider = Gui::Application::Instance->getViewProvider(obj);
|
||||
if (!viewProvider)
|
||||
continue;
|
||||
|
||||
|
||||
bboxAction.apply(viewProvider->getRoot());
|
||||
bbox.extendBy(bboxAction.getBoundingBox());
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
if(bbox.getSize().length() < 1e-7) {
|
||||
bbox = SbBox3f(10., 10., 10., 10., 10., 10.);
|
||||
}
|
||||
|
||||
|
||||
//get the bounding box values
|
||||
SbVec3f size = bbox.getSize()*1.3;
|
||||
SbVec3f max = bbox.getMax()*1.3;
|
||||
SbVec3f min = bbox.getMin()*1.3;
|
||||
|
||||
|
||||
auto origins = part->getObjectsOfType(App::Origin::getClassTypeId());
|
||||
if (origins.empty())
|
||||
return;
|
||||
App::Origin* origin = dynamic_cast<App::Origin*>(origins.front());
|
||||
if(!origin)
|
||||
return;
|
||||
|
||||
|
||||
//get the planes and set their values
|
||||
std::vector<App::DocumentObject*> planes = origin->getObjectsOfType(App::Plane::getClassTypeId());
|
||||
for (std::vector<App::DocumentObject*>::const_iterator p = planes.begin(); p != planes.end(); p++) {
|
||||
|
||||
|
||||
Gui::ViewProviderPlane* vp = dynamic_cast<Gui::ViewProviderPlane*>(Gui::Application::Instance->getViewProvider(*p));
|
||||
if(vp) {
|
||||
if (strcmp(App::Part::BaseplaneTypes[0], dynamic_cast<App::Plane*>(*p)->PlaneType.getValue()) == 0)
|
||||
vp->Size.setValue(std::max(std::abs(std::min(min[0], min[1])),std::max(max[0], max[1])));
|
||||
else if (strcmp(App::Part::BaseplaneTypes[1], dynamic_cast<App::Plane*>(*p)->PlaneType.getValue()) == 0)
|
||||
vp->Size.setValue(std::max(std::abs(std::min(min[0], min[2])),std::max(max[0], max[2])));
|
||||
else if (strcmp(App::Part::BaseplaneTypes[2], dynamic_cast<App::Plane*>(*p)->PlaneType.getValue()) == 0)
|
||||
vp->Size.setValue(std::max(std::abs(std::min(min[1], min[2])),std::max(max[1], max[2])));
|
||||
else if (strcmp(App::Part::BaseplaneTypes[2], dynamic_cast<App::Plane*>(*p)->PlaneType.getValue()) == 0)
|
||||
vp->Size.setValue(std::max(std::abs(std::min(min[1], min[2])),std::max(max[1], max[2])));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//get the lines and set their values
|
||||
std::vector<App::DocumentObject*> lines = origin->getObjectsOfType(App::Line::getClassTypeId());
|
||||
for (std::vector<App::DocumentObject*>::const_iterator p = lines.begin(); p != lines.end(); p++) {
|
||||
|
||||
|
||||
Gui::ViewProviderLine* vp = dynamic_cast<Gui::ViewProviderLine*>(Gui::Application::Instance->getViewProvider(*p));
|
||||
if(vp) {
|
||||
if (strcmp(App::Part::BaselineTypes[0], dynamic_cast<App::Line*>(*p)->LineType.getValue()) == 0)
|
||||
vp->Size.setValue(std::max(std::abs(std::min(min[0], min[1])),std::max(max[0], max[1])));
|
||||
else if (strcmp(App::Part::BaselineTypes[1], dynamic_cast<App::Line*>(*p)->LineType.getValue()) == 0)
|
||||
else if (strcmp(App::Part::BaselineTypes[1], dynamic_cast<App::Line*>(*p)->LineType.getValue()) == 0)
|
||||
vp->Size.setValue(std::max(std::abs(std::min(min[0], min[2])),std::max(max[0], max[2])));
|
||||
else if (strcmp(App::Part::BaselineTypes[2], dynamic_cast<App::Line*>(*p)->LineType.getValue()) == 0)
|
||||
vp->Size.setValue(std::max(std::abs(std::min(min[1], min[2])),std::max(max[1], max[2])));
|
||||
|
@ -169,9 +169,10 @@ void ViewProviderPart::onObjectChanged(const App::DocumentObject& obj, const App
|
|||
|
||||
bool ViewProviderPart::doubleClicked(void)
|
||||
{
|
||||
if(Workbench.getValue() != "")
|
||||
if(Workbench.getStrValue() != "") {
|
||||
// assure the given workbench
|
||||
Gui::Command::assureWorkbench( Workbench.getValue() );
|
||||
}
|
||||
|
||||
//make the part the active one
|
||||
Gui::Command::doCommand(Gui::Command::Gui, "Gui.activeView().setActiveObject('%s', App.activeDocument().%s)", PARTKEY, this->getObject()->getNameInDocument());
|
||||
|
@ -232,49 +233,49 @@ void ViewProviderPart::setUpPart(const App::Part *part)
|
|||
Gui::Command::doCommand(Gui::Command::Doc,"Origin = App.activeDocument().addObject('App::Origin','%s')", oname.c_str());
|
||||
Gui::Command::doCommand(Gui::Command::Doc,"Origin.Label = '%s'", QObject::tr("Origin").toStdString().c_str());
|
||||
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.addObject(Origin)", part->getNameInDocument());
|
||||
|
||||
|
||||
// Add the planes ...
|
||||
std::string pname = part->getDocument()->getUniqueObjectName(App::Part::BaseplaneTypes[0]);
|
||||
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().addObject('App::Plane','%s')", pname.c_str());
|
||||
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().ActiveObject.PlaneType = '%s'", App::Part::BaseplaneTypes[0]);
|
||||
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().ActiveObject.Label = '%s'", QObject::tr("XY-Plane").toStdString().c_str());
|
||||
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.addObject(App.activeDocument().ActiveObject)", oname.c_str());
|
||||
|
||||
|
||||
pname = part->getDocument()->getUniqueObjectName(App::Part::BaseplaneTypes[1]);
|
||||
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().addObject('App::Plane','%s')", pname.c_str());
|
||||
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().ActiveObject.Placement = App.Placement(App.Vector(),App.Rotation(App.Vector(1,0,0),90))");
|
||||
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().ActiveObject.Placement = App.Placement(App.Vector(),App.Rotation(App.Vector(0,1,1),180))");
|
||||
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().ActiveObject.PlaneType = '%s'", App::Part::BaseplaneTypes[1]);
|
||||
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().ActiveObject.Label = '%s'", QObject::tr("XZ-Plane").toStdString().c_str());
|
||||
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.addObject(App.activeDocument().ActiveObject)", oname.c_str());
|
||||
|
||||
|
||||
pname = part->getDocument()->getUniqueObjectName(App::Part::BaseplaneTypes[2]);
|
||||
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().addObject('App::Plane','%s')", pname.c_str());
|
||||
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().ActiveObject.Placement = App.Placement(App.Vector(),App.Rotation(App.Vector(1,1,1),120))");
|
||||
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().ActiveObject.PlaneType = '%s'", App::Part::BaseplaneTypes[2]);
|
||||
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().ActiveObject.Label = '%s'", QObject::tr("YZ-Plane").toStdString().c_str());
|
||||
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.addObject(App.activeDocument().ActiveObject)", oname.c_str());
|
||||
|
||||
|
||||
// Add the lines ...
|
||||
std::string lname = part->getDocument()->getUniqueObjectName(App::Part::BaselineTypes[0]);
|
||||
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().addObject('App::Line','%s')", lname.c_str());
|
||||
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().ActiveObject.LineType = '%s'", App::Part::BaselineTypes[0]);
|
||||
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().ActiveObject.Label = '%s'", QObject::tr("X-Axis").toStdString().c_str());
|
||||
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.addObject(App.activeDocument().ActiveObject)", oname.c_str());
|
||||
|
||||
|
||||
lname = part->getDocument()->getUniqueObjectName(App::Part::BaselineTypes[1]);
|
||||
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().addObject('App::Line','%s')", lname.c_str());
|
||||
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().ActiveObject.Placement = App.Placement(App.Vector(),App.Rotation(App.Vector(0,0,1),90))");
|
||||
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().ActiveObject.LineType = '%s'", App::Part::BaselineTypes[1]);
|
||||
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().ActiveObject.Label = '%s'", QObject::tr("Y-Axis").toStdString().c_str());
|
||||
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.addObject(App.activeDocument().ActiveObject)", oname.c_str());
|
||||
|
||||
|
||||
lname = part->getDocument()->getUniqueObjectName(App::Part::BaselineTypes[2]);
|
||||
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().addObject('App::Line','%s')", lname.c_str());
|
||||
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().ActiveObject.Placement = App.Placement(App.Vector(),App.Rotation(App.Vector(0,1,0),90))");
|
||||
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().ActiveObject.LineType = '%s'", App::Part::BaselineTypes[2]);
|
||||
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().ActiveObject.Label = '%s'", QObject::tr("Z-Axis").toStdString().c_str());
|
||||
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.addObject(App.activeDocument().ActiveObject)", oname.c_str());
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user