add base lines

This commit is contained in:
Stefan Tröger
2015-05-05 07:05:09 +02:00
parent 09660ea84d
commit b401f07bdf
12 changed files with 735 additions and 2 deletions

View File

@@ -30,11 +30,13 @@
#include <App/Part.h>
#include <App/Plane.h>
#include <App/Line.h>
#include <App/Document.h>
/// Here the FreeCAD includes sorted by Base,App,Gui......
#include "ViewProviderPart.h"
#include "ViewProviderPlane.h"
#include "ViewProviderLine.h"
#include "Application.h"
#include "Command.h"
#include "BitmapFactory.h"
@@ -89,7 +91,9 @@ 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) && obj.getTypeId() != App::Plane::getClassTypeId()) {
if(static_cast<App::Part*>(pcObject)->hasObject(&obj) &&
obj.getTypeId() != App::Plane::getClassTypeId() &&
obj.getTypeId() != App::Line::getClassTypeId()) {
View3DInventorViewer* viewer = static_cast<View3DInventor*>(this->getActiveView())->getViewer();
SoGetBoundingBoxAction bboxAction(viewer->getSoRenderManager()->getViewportRegion());
@@ -97,7 +101,8 @@ void ViewProviderPart::onObjectChanged(const App::DocumentObject& obj, const App
//calculate for everything but planes
SbBox3f bbox(0.0001f,0.0001f,0.0001f,0.0001f,0.0001f,0.0001f);
for(App::DocumentObject* obj : part->getObjects()) {
if(obj->getTypeId() != App::Plane::getClassTypeId()) {
if(obj->getTypeId() != App::Plane::getClassTypeId() &&
obj->getTypeId() != App::Line::getClassTypeId() ) {
bboxAction.apply(Gui::Application::Instance->getViewProvider(obj)->getRoot());
bbox.extendBy(bboxAction.getBoundingBox());
}
@@ -138,6 +143,37 @@ void ViewProviderPart::onObjectChanged(const App::DocumentObject& obj, const App
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 = part->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 (strcmp(App::Part::BaselineTypes[0], dynamic_cast<App::Line*>(*p)->getNameInDocument()) == 0) {
Base::Placement cpl = dynamic_cast<App::Line*>(*p)->Placement.getValue();
cpl = Base::Placement(-cpl.getPosition() + Base::Vector3d((max[0]+min[0])/2., (max[1]+min[1])/2., 0), Base::Rotation());
//dynamic_cast<App::Plane*>(*p)->Placement.setValue(cpl);
if(vp)
vp->Size.setValue(std::max(std::abs(std::min(min[0], min[1])),std::max(max[0], max[1])));
}
if (strcmp(App::Part::BaselineTypes[1], dynamic_cast<App::Line*>(*p)->getNameInDocument()) == 0) {
Base::Placement cpl = dynamic_cast<App::Line*>(*p)->Placement.getValue();
cpl = Base::Placement(-cpl.getPosition() + Base::Vector3d((max[0]+min[0])/2., 0, (max[2]+min[2])/2.), Base::Rotation());
//dynamic_cast<App::Plane*>(*p)->Placement.setValue(cpl);
if(vp)
vp->Size.setValue(std::max(std::abs(std::min(min[0], min[2])),std::max(max[0], max[2])));
}
if (strcmp(App::Part::BaselineTypes[2], dynamic_cast<App::Line*>(*p)->getNameInDocument()) == 0) {
Base::Placement cpl = dynamic_cast<App::Line*>(*p)->Placement.getValue();
cpl = Base::Placement(-cpl.getPosition() + Base::Vector3d(0, (max[1]+min[1])/2., (max[2]+min[2])/2.), Base::Rotation());
//dynamic_cast<App::Plane*>(*p)->Placement.setValue(cpl);
if(vp)
vp->Size.setValue(std::max(std::abs(std::min(min[1], min[2])),std::max(max[1], max[2])));
}
}
}
}
@@ -219,6 +255,23 @@ void ViewProviderPart::setUpPart(const App::Part *part)
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.addObject(App.activeDocument().ActiveObject)", part->getNameInDocument());
//Gui::Command::doCommand(Gui::Command::Doc,"OGroup.addObject(App.activeDocument().ActiveObject)");
// Add the lines ...
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().addObject('App::Line','%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)", part->getNameInDocument());
//Gui::Command::doCommand(Gui::Command::Doc,"OGroup.addObject(App.activeDocument().ActiveObject)");
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().addObject('App::Line','%s')", App::Part::BaselineTypes[1]);
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.Label = '%s'", QObject::tr("Y-Axis").toStdString().c_str());
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.addObject(App.activeDocument().ActiveObject)", part->getNameInDocument());
//Gui::Command::doCommand(Gui::Command::Doc,"OGroup.addObject(App.activeDocument().ActiveObject)");
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().addObject('App::Line','%s')", App::Part::BaselineTypes[2]);
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.Label = '%s'", QObject::tr("Z-Axis").toStdString().c_str());
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.addObject(App.activeDocument().ActiveObject)", part->getNameInDocument());
//Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.addObject(OGroup)", part->getNameInDocument());
// TODO: Fold the group (is that possible through the Python interface?)
}