OriginGroup: add new abstraction layer between the Part and the GeoFeatureGroup

This commit is contained in:
Alexander Golubev
2015-09-02 07:22:54 +03:00
committed by Stefan Tröger
parent 59ca9212d6
commit 2c2d155ee9
33 changed files with 835 additions and 557 deletions

View File

@@ -79,25 +79,6 @@
// return PartDesignGui::ActivePartObject->getPyObject();
//}
void setUpPart(App::Part *part);
static PyObject * setUpPart(PyObject *self, PyObject *args)
{
PyObject *object=0;
if (! PyArg_ParseTuple(args,"O!",&(App::PartPy::Type), &object) )
return NULL;
App::Part* part = static_cast<App::PartPy*>(object)->getPartPtr();
// Should be set!
assert(part);
PartDesignGui::setUpPart(part);
Py_Return;
}
/* registration table */
struct PyMethodDef Assembly_methods[] = {
//{"setActiveBody" ,setActiveBody ,METH_VARARGS,
@@ -106,8 +87,5 @@ struct PyMethodDef Assembly_methods[] = {
//{"getActiveBody" ,getActiveBody ,METH_NOARGS,
// "getActiveBody() -- Get the PartBody object in work."},
{"setUpPart" ,setUpPart ,METH_VARARGS,
"setUpPart(Part) -- Sets a empty part object up for usage in PartDesign."},
{NULL, NULL} /* end of table marker */
};

View File

@@ -38,54 +38,9 @@
#include <Mod/PartDesign/App/BodyPy.h>
#include "ViewProviderBody.h"
#include "Workbench.h"
#include "Utils.h"
namespace PartDesignGui {
// The names of the base planes. Note: The user-visible label is different from this
const char* BaseplaneNames[3] = {"BaseplaneXY", "BaseplaneXZ", "BaseplaneYZ"};
}
<<<<<<< 4db2e50e38d4a9c01764fa8dedb78231fc64faee:src/Mod/Assembly/App/AppAssemblyPy.cpp
static PyObject * setActiveBody(PyObject *self, PyObject *args)
{
PyObject *object=0;
if (PyArg_ParseTuple(args,"|O!",&(PartDesign::BodyPy::Type), &object)&& object) {
PartDesign::Body* Item = static_cast<PartDesign::BodyPy*>(object)->getBodyPtr();
// Should be set!
assert(Item);
// Set old body inactive if we are activating another body in the same document
if ((PartDesignGui::ActivePartObject != NULL) &&
(PartDesignGui::ActivePartObject->getDocument() == Item->getDocument()))
PartDesignGui::ActivePartObject->IsActive.setValue(false);
PartDesignGui::ActivePartObject = Item;
PartDesignGui::ActiveAppDoc = Item->getDocument();
PartDesignGui::ActiveGuiDoc = Gui::Application::Instance->getDocument(PartDesignGui::ActiveAppDoc);
PartDesignGui::ActiveVp = dynamic_cast<Gui::ViewProviderDocumentObject*> (PartDesignGui::ActiveGuiDoc->getViewProvider(Item));
PartDesignGui::ActiveVp->show();
Item->IsActive.setValue(true);
} else {
// This handles the case of deactivating the workbench
PartDesignGui::ActivePartObject=0;
PartDesignGui::ActiveGuiDoc =0;
PartDesignGui::ActiveAppDoc =0;
PartDesignGui::ActiveVp =0;
}
Py_Return;
}
static PyObject * getActiveBody(PyObject *, PyObject *)
{
if (PartDesignGui::ActivePartObject == NULL) {
return Py::_None();
}
return PartDesignGui::ActivePartObject->getPyObject();
}
=======
//static PyObject * setActiveBody(PyObject *self, PyObject *args)
//{
// PyObject *object=0;
@@ -123,43 +78,21 @@ static PyObject * getActiveBody(PyObject *, PyObject *)
//
// return PartDesignGui::ActivePartObject->getPyObject();
//}
>>>>>>> Changing active object handling in PartDesign:src/Mod/PartDesign/Gui/AppPartDesignGuiPy.cpp
void setUpPart(App::Part *part);
static PyObject * setUpPart(PyObject *self, PyObject *args)
{
PyObject *object=0;
if (! PyArg_ParseTuple(args,"O!",&(App::PartPy::Type), &object) )
return NULL;
App::Part* part = static_cast<App::PartPy*>(object)->getPartPtr();
// Should be set!
assert(part);
PartDesignGui::Workbench::setUpPart(part);
Py_Return;
}
/* registration table */
<<<<<<< 4db2e50e38d4a9c01764fa8dedb78231fc64faee:src/Mod/Assembly/App/AppAssemblyPy.cpp
struct PyMethodDef Assembly_methods[] = {
{"setActiveBody" ,setActiveBody ,METH_VARARGS,
"setActiveBody(BodyObject) -- Set the PartBody object in work."},
=======
struct PyMethodDef PartDesignGui_Import_methods[] = {
//{"setActiveBody" ,setActiveBody ,METH_VARARGS,
// "setActiveBody(BodyObject) -- Set the PartBody object in work."},
>>>>>>> Changing active object handling in PartDesign:src/Mod/PartDesign/Gui/AppPartDesignGuiPy.cpp
//{"getActiveBody" ,getActiveBody ,METH_NOARGS,
// "getActiveBody() -- Get the PartBody object in work."},
<<<<<<< f03c0f9bdef9886ee45a086b02fa7ebaa99b6825:src/Mod/Assembly/App/AppAssemblyPy.cpp
{"setUpPart" ,setUpPart ,METH_VARARGS,
"setUpPart(Part) -- Sets a empty part object up for usage in PartDesign."},
{NULL, NULL} /* end of table marker */
=======
{NULL, NULL} /* end of table marker */
>>>>>>> OriginGroup: add new abstraction layer between the Part and the GeoFeatureGroup:src/Mod/PartDesign/Gui/AppPartDesignGuiPy.cpp
};

View File

@@ -35,6 +35,7 @@
#include <algorithm>
#include <App/DocumentObjectGroup.h>
#include <App/Origin.h>
#include <App/OriginFeature.h>
#include <App/Part.h>
#include <Gui/Application.h>
@@ -43,7 +44,7 @@
#include <Gui/Selection.h>
#include <Gui/MainWindow.h>
#include <Gui/Document.h>
#include <Mod/Sketcher/App/SketchObject.h>
#include <Mod/PartDesign/App/Body.h>
@@ -236,7 +237,7 @@ CmdPartDesignNewSketch::CmdPartDesignNewSketch()
void CmdPartDesignNewSketch::activated(int iMsg)
{
App::Document *doc = getDocument ();
PartDesign::Body *pcActiveBody = PartDesignGui::getBody(
PartDesign::Body *pcActiveBody = PartDesignGui::getBody(
/*messageIfNot = */ PartDesignGui::assureModernWorkflow ( doc ) );
// No PartDesign feature without Body past FreeCAD 0.13
@@ -307,18 +308,8 @@ void CmdPartDesignNewSketch::activated(int iMsg)
}
if (!pcActiveBody->hasFeature(obj)) {
// TODO check what the heck is going on here (2015-08-31, Fat-Zer)
bool isBasePlane = false;
if(obj->isDerivedFrom(App::Plane::getClassTypeId())) {
App::Plane* pfeat = static_cast<App::Plane*>(obj);
for (unsigned i = 0; i < 3; i++) {
if (strcmp(App::Part::BaseplaneTypes[i], pfeat->Role.getValue()) == 0) {
isBasePlane = true;
break;
}
}
}
if (!isBasePlane) {
if ( !obj->isDerivedFrom ( App::Plane::getClassTypeId() ) ) {
// TODO check here if the plane associated with right part/body (2015-09-01, Fat-Zer)
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Selection from other body"),
QObject::tr("You have to select a face or plane from the active body!"));
return;
@@ -346,55 +337,48 @@ void CmdPartDesignNewSketch::activated(int iMsg)
}
else {
// Get a valid plane from the user
std::vector<PartDesignGui::TaskFeaturePick::featureStatus> status;
std::vector<App::DocumentObject*> planes = getDocument()->getObjectsOfType(App::Plane::getClassTypeId());
std::vector<App::DocumentObject*> planestmp = getDocument()->getObjectsOfType(PartDesign::Plane::getClassTypeId());
planes.insert(planes.end(), planestmp.begin(), planestmp.end());
unsigned validPlanes = 0;
std::vector<App::DocumentObject*>::const_iterator firstValidPlane = planes.end();
App::Part* pcActivePart = Gui::Application::Instance->activeView()->getActiveObject<App::Part*>(PARTKEY);
for (std::vector<App::DocumentObject*>::iterator p = planes.begin(); p != planes.end(); p++) {
// Check whether this plane is a base plane
bool base = false;
if((*p)->isDerivedFrom(App::Plane::getClassTypeId())) {
App::Plane* pfeat = static_cast<App::Plane*>(*p);
for (unsigned i = 0; i < 3; i++) {
if (strcmp(App::Part::BaseplaneTypes[i], pfeat->Role.getValue()) == 0) {
if(pcActivePart->hasObject(pfeat, true))
status.push_back(PartDesignGui::TaskFeaturePick::basePlane);
else
status.push_back(PartDesignGui::TaskFeaturePick::invalidShape);
if (firstValidPlane == planes.end())
firstValidPlane = p;
validPlanes++;
base = true;
break;
}
std::vector<App::DocumentObject*> planes;
std::vector<PartDesignGui::TaskFeaturePick::featureStatus> status;
// Baseplanes are preaprooved
if ( pcActivePart ) {
try {
for ( auto plane: pcActivePart->getOrigin ()->planes() ) {
planes.push_back (plane);
status.push_back(PartDesignGui::TaskFeaturePick::basePlane);
validPlanes++;
}
} catch (const Base::Exception &ex) {
Base::Console().Error ("%s\n", ex.what() );
}
if (base) continue;
}
std::vector<App::DocumentObject*> datumPlanes =
getDocument()->getObjectsOfType(PartDesign::Plane::getClassTypeId());
for (auto plane: datumPlanes) {
planes.push_back ( plane );
// Check whether this plane belongs to the active body
if (!pcActiveBody->hasFeature(*p)) {
if(pcActivePart->hasObject(*p, true))
if (!pcActiveBody->hasFeature(plane)) {
if ( pcActivePart && pcActivePart->hasObject ( plane, true ) ) {
status.push_back(PartDesignGui::TaskFeaturePick::otherBody);
else
} else {
status.push_back(PartDesignGui::TaskFeaturePick::otherPart);
}
continue;
} else {
if (pcActiveBody->isAfterInsertPoint(*p)) {
if (pcActiveBody->isAfterInsertPoint ( plane ) ) {
status.push_back(PartDesignGui::TaskFeaturePick::afterTip);
continue;
}
}
// All checks passed - found a valid plane
if (firstValidPlane == planes.end())
firstValidPlane = p;
validPlanes++;
status.push_back(PartDesignGui::TaskFeaturePick::validFeature);
}
@@ -1409,10 +1393,11 @@ void CmdPartDesignMirrored::activated(int iMsg)
Gui::Command::doCommand(Doc,"App.activeDocument().%s.MirrorPlane = (App.activeDocument().%s, [\"V_Axis\"])",
FeatName.c_str(), sketch->getNameInDocument());
}
else {
doCommand(Doc,"App.activeDocument().%s.MirrorPlane = (App.activeDocument().%s, [\"\"])", FeatName.c_str(),
App::Part::BaseplaneTypes[0]);
}
// TODO Check if default mirrored plane correctly set (2015-09-01, Fat-Zer)
// else {
// doCommand(Doc,"App.activeDocument().%s.MirrorPlane = (App.activeDocument().%s, [\"\"])", FeatName.c_str(),
// App::Part::BaseplaneTypes[0]);
// }
finishTransformed(cmd, FeatName);
};
@@ -1456,10 +1441,11 @@ void CmdPartDesignLinearPattern::activated(int iMsg)
doCommand(Doc,"App.activeDocument().%s.Direction = (App.activeDocument().%s, [\"H_Axis\"])",
FeatName.c_str(), sketch->getNameInDocument());
}
else {
doCommand(Doc,"App.activeDocument().%s.Direction = (App.activeDocument().%s, [\"\"])", FeatName.c_str(),
App::Part::BaselineTypes[0]);
}
// TODO Check if default direction correctly set (2015-09-01, Fat-Zer)
// else {
// doCommand(Doc,"App.activeDocument().%s.Direction = (App.activeDocument().%s, [\"\"])", FeatName.c_str(),
// App::Part::BaselineTypes[0]);
// }
doCommand(Doc,"App.activeDocument().%s.Length = 100", FeatName.c_str());
doCommand(Doc,"App.activeDocument().%s.Occurrences = 2", FeatName.c_str());
@@ -1505,10 +1491,11 @@ void CmdPartDesignPolarPattern::activated(int iMsg)
doCommand(Doc,"App.activeDocument().%s.Axis = (App.activeDocument().%s, [\"N_Axis\"])",
FeatName.c_str(), sketch->getNameInDocument());
}
else {
doCommand(Doc,"App.activeDocument().%s.Axis = (App.activeDocument().%s, [\"\"])", FeatName.c_str(),
App::Part::BaselineTypes[0]);
}
// TODO Check if default axis correctly set (2015-09-01, Fat-Zer)
// else {
// doCommand(Doc,"App.activeDocument().%s.Axis = (App.activeDocument().%s, [\"\"])", FeatName.c_str(),
// App::Part::BaselineTypes[0]);
// }
doCommand(Doc,"App.activeDocument().%s.Angle = 360", FeatName.c_str());
doCommand(Doc,"App.activeDocument().%s.Occurrences = 2", FeatName.c_str());

View File

@@ -101,8 +101,8 @@ void CmdPartDesignPart::activated(int iMsg)
// TODO We really must to set label ourselfs? (2015-08-17, Fat-Zer)
doCommand(Doc,"App.activeDocument().%s.Label = '%s'", PartName.c_str(),
QObject::tr(PartName.c_str()).toUtf8().data());
PartDesignGui::setUpPart(dynamic_cast<App::Part *>(getDocument()->getObject(PartName.c_str())));
doCommand(Gui::Command::Gui, "Gui.activeView().setActiveObject('%s', App.activeDocument().%s)", PARTKEY, PartName.c_str());
doCommand(Gui::Command::Gui, "Gui.activeView().setActiveObject('%s', App.activeDocument().%s)",
PARTKEY, PartName.c_str());
updateActive();
}

View File

@@ -209,17 +209,19 @@ TaskDatumParameters::TaskDatumParameters(ViewProviderDatum *DatumView,QWidget *p
ui->listOfModes->blockSignals(false);
updateUI();
updateListOfModes(eMapMode(pcDatum->MapMode.getValue()));
//temporary show coordinate systems for selection
App::Part* part = getPartFor(DatumView->getObject(), false);
if(part) {
auto app_origin = part->getObjectsOfType(App::Origin::getClassTypeId());
if(!app_origin.empty()) {
ViewProviderOrigin* origin;
origin = static_cast<ViewProviderOrigin*>(Gui::Application::Instance->getViewProvider(app_origin[0]));
origin->setTemporaryVisibility(true, true);
}
}
if(part) {
try {
App::Origin *origin = part->getOrigin();
ViewProviderOrigin* vpOrigin;
vpOrigin = static_cast<ViewProviderOrigin*>(Gui::Application::Instance->getViewProvider(origin));
vpOrigin->setTemporaryVisibility(true, true);
} catch (const Base::Exception &ex) {
Base::Console().Error ("%s\n", ex.what () );
}
}
if (pcDatum->Support.getSize() == 0)
autoNext = true;
else
@@ -771,14 +773,16 @@ TaskDatumParameters::~TaskDatumParameters()
//end temporary view mode of coordinate system
App::Part* part = getPartFor(DatumView->getObject(), false);
if(part) {
auto app_origin = part->getObjectsOfType(App::Origin::getClassTypeId());
if(!app_origin.empty()) {
ViewProviderOrigin* origin;
origin = static_cast<ViewProviderOrigin*>(Gui::Application::Instance->getViewProvider(app_origin[0]));
origin->resetTemporaryVisibility();
}
try {
App::Origin *origin = part->getOrigin();
ViewProviderOrigin* vpOrigin;
vpOrigin = static_cast<ViewProviderOrigin*>(Gui::Application::Instance->getViewProvider(origin));
vpOrigin->resetTemporaryVisibility();
} catch (const Base::Exception &ex) {
Base::Console().Error ("%s\n", ex.what () );
}
}
delete ui;
}

View File

@@ -89,7 +89,7 @@ TaskFeaturePick::TaskFeaturePick(std::vector<App::DocumentObject*>& objects,
enum { axisBit=0, planeBit = 1};
// Note generally there shouldn't be more then one origin
// NOTE: generally there shouldn't be more then one origin
std::map <App::Origin*, std::bitset<2> > originVisStatus;
auto statusIt = status.cbegin();
@@ -110,18 +110,24 @@ TaskFeaturePick::TaskFeaturePick(std::vector<App::DocumentObject*>& objects,
} else if ( (*objIt)->isDerivedFrom ( App::Line::getClassTypeId () ) ) {
originVisStatus[ origin ].set (axisBit, true);
}
Gui::ViewProviderOrigin* vpo = static_cast<Gui::ViewProviderOrigin*> (
Gui::Application::Instance->getViewProvider(*objIt) );
if (vpo) {
vpo->setTemporaryVisibility( originVisStatus[origin][axisBit],
originVisStatus[origin][planeBit]);
}
origins.push_back(vpo);
}
}
}
// Setup the origin's temporary visability
for ( const auto & originPair: originVisStatus ) {
const auto &origin = originPair.first;
const auto &status = originPair.second;
Gui::ViewProviderOrigin* vpo = static_cast<Gui::ViewProviderOrigin*> (
Gui::Application::Instance->getViewProvider ( origin ) );
if (vpo) {
vpo->setTemporaryVisibility( originVisStatus[origin][axisBit],
originVisStatus[origin][planeBit]);
origins.push_back(vpo);
}
}
// TODO may be update origin API to show only some objects (2015-08-31, Fat-Zer)
groupLayout()->addWidget(proxy);

View File

@@ -166,12 +166,14 @@ void TaskLinearPatternParameters::setupUI()
//show the parts coordinate system axis for selection
App::Part* part = getPartFor(getObject(), false);
if(part) {
auto app_origin = part->getObjectsOfType(App::Origin::getClassTypeId());
if(!app_origin.empty()) {
ViewProviderOrigin* origin;
origin = static_cast<ViewProviderOrigin*>(Gui::Application::Instance->getViewProvider(app_origin[0]));
origin->setTemporaryVisibility(true, false);
if(part) {
try {
App::Origin *origin = part->getOrigin();
ViewProviderOrigin* vpOrigin;
vpOrigin = static_cast<ViewProviderOrigin*>(Gui::Application::Instance->getViewProvider(origin));
vpOrigin->setTemporaryVisibility(true, false);
} catch (const Base::Exception &ex) {
Base::Console().Error ("%s\n", ex.what () );
}
}
}
@@ -223,29 +225,20 @@ void TaskLinearPatternParameters::onSelectionChanged(const Gui::SelectionChanges
removeItemFromListWidget(ui->listWidgetFeatures, msg.pObjectName);
exitSelectionMode();
} else if (selectionMode == reference) {
// Note: ReferenceSelection has already checked the selection for validity
} else {
// TODO check if this works correctly (2015-09-01, Fat-Zer)
exitSelectionMode();
std::vector<std::string> directions;
App::DocumentObject* selObj;
PartDesign::LinearPattern* pcLinearPattern = static_cast<PartDesign::LinearPattern*>(getObject());
getReferencedSelection(pcLinearPattern, msg, selObj, directions);
pcLinearPattern->Direction.setValue(selObj, directions);
// Note: ReferenceSelection has already checked the selection for validity
if ( selectionMode == reference || selObj->isDerivedFrom ( App::Line::getClassTypeId () ) ) {
pcLinearPattern->Direction.setValue(selObj, directions);
recomputeFeature();
updateUI();
} else if( strstr(msg.pObjectName, App::Part::BaselineTypes[0]) == nullptr ||
strstr(msg.pObjectName, App::Part::BaselineTypes[1]) == nullptr ||
strstr(msg.pObjectName, App::Part::BaselineTypes[2]) == nullptr) {
std::vector<std::string> directions;
App::DocumentObject* selObj;
PartDesign::LinearPattern* pcLinearPattern = static_cast<PartDesign::LinearPattern*>(getObject());
getReferencedSelection(pcLinearPattern, msg, selObj, directions);
pcLinearPattern->Direction.setValue(selObj, directions);
recomputeFeature();
updateUI();
recomputeFeature();
updateUI();
}
}
}
}
@@ -366,12 +359,14 @@ TaskLinearPatternParameters::~TaskLinearPatternParameters()
//hide the parts coordinate system axis for selection
App::Part* part = getPartFor(getObject(), false);
if(part) {
auto app_origin = part->getObjectsOfType(App::Origin::getClassTypeId());
if(!app_origin.empty()) {
ViewProviderOrigin* origin;
origin = static_cast<ViewProviderOrigin*>(Gui::Application::Instance->getViewProvider(app_origin[0]));
origin->resetTemporaryVisibility();
}
try {
App::Origin *origin = part->getOrigin();
ViewProviderOrigin* vpOrigin;
vpOrigin = static_cast<ViewProviderOrigin*>(Gui::Application::Instance->getViewProvider(origin));
vpOrigin->resetTemporaryVisibility();
} catch (const Base::Exception &ex) {
Base::Console().Error ("%s\n", ex.what () );
}
}
delete ui;

View File

@@ -132,22 +132,23 @@ void TaskMirroredParameters::setupUI()
this->planeLinks.setCombo(*(ui->comboPlane));
ui->comboPlane->setEnabled(true);
App::DocumentObject* sketch = getSketchObject();
if (!sketch->isDerivedFrom(Part::Part2DObject::getClassTypeId()))
sketch = 0;
this->fillPlanesCombo(planeLinks,static_cast<Part::Part2DObject*>(sketch));
updateUI();
//show the parts coordinate system axis for selection
App::Part* part = getPartFor(getObject(), false);
if(part) {
auto app_origin = part->getObjectsOfType(App::Origin::getClassTypeId());
if(!app_origin.empty()) {
ViewProviderOrigin* origin;
origin = static_cast<ViewProviderOrigin*>(Gui::Application::Instance->getViewProvider(app_origin.front() ));
origin->setTemporaryVisibility(true, false);
try {
App::Origin *origin = part->getOrigin();
ViewProviderOrigin* vpOrigin;
vpOrigin = static_cast<ViewProviderOrigin*>(Gui::Application::Instance->getViewProvider(origin));
vpOrigin->setTemporaryVisibility(true, false);
} catch (const Base::Exception &ex) {
Base::Console().Error ("%s\n", ex.what () );
}
}
}
@@ -179,30 +180,20 @@ void TaskMirroredParameters::onSelectionChanged(const Gui::SelectionChanges& msg
else
removeItemFromListWidget(ui->listWidgetFeatures, msg.pObjectName);
exitSelectionMode();
} else if (selectionMode == reference) {
// Note: ReferenceSelection has already checked the selection for validity
} else {
// TODO checkme (2015-09-01, Fat-Zer)
exitSelectionMode();
std::vector<std::string> mirrorPlanes;
App::DocumentObject* selObj;
PartDesign::Mirrored* pcMirrored = static_cast<PartDesign::Mirrored*>(getObject());
getReferencedSelection(pcMirrored, msg, selObj, mirrorPlanes);
pcMirrored->MirrorPlane.setValue(selObj, mirrorPlanes);
// Note: ReferenceSelection has already checked the selection for validity
if ( selectionMode == reference || selObj->isDerivedFrom ( App::Plane::getClassTypeId () ) ) {
pcMirrored->MirrorPlane.setValue(selObj, mirrorPlanes);
recomputeFeature();
updateUI();
} else if( strstr(msg.pObjectName, App::Part::BaseplaneTypes[0]) == nullptr ||
strstr(msg.pObjectName, App::Part::BaseplaneTypes[1]) == nullptr ||
strstr(msg.pObjectName, App::Part::BaseplaneTypes[2]) == nullptr) {
std::vector<std::string> planes;
App::DocumentObject* selObj;
PartDesign::Mirrored* pcMirrored = static_cast<PartDesign::Mirrored*>(getObject());
getReferencedSelection(pcMirrored, msg, selObj, planes);
pcMirrored->MirrorPlane.setValue(selObj, planes);
recomputeFeature();
updateUI();
recomputeFeature();
updateUI();
}
}
}
}
@@ -278,15 +269,16 @@ TaskMirroredParameters::~TaskMirroredParameters()
//hide the parts coordinate system axis for selection
App::Part* part = getPartFor(getObject(), false);
if(part) {
auto app_origin = part->getObjectsOfType(App::Origin::getClassTypeId());
if(!app_origin.empty()) {
ViewProviderOrigin* origin;
origin = static_cast<ViewProviderOrigin*>(Gui::Application::Instance->getViewProvider(app_origin[0]));
origin->resetTemporaryVisibility();
}
try {
App::Origin *origin = part->getOrigin();
ViewProviderOrigin* vpOrigin;
vpOrigin = static_cast<ViewProviderOrigin*>(Gui::Application::Instance->getViewProvider(origin));
vpOrigin->resetTemporaryVisibility();
} catch (const Base::Exception &ex) {
Base::Console().Error ("%s\n", ex.what () );
}
}
delete ui;
if (proxy)
delete proxy;

View File

@@ -161,12 +161,14 @@ void TaskPolarPatternParameters::setupUI()
//show the parts coordinate system axis for selection
App::Part* part = getPartFor(getObject(), false);
if(part) {
auto app_origin = part->getObjectsOfType(App::Origin::getClassTypeId());
if(!app_origin.empty()) {
ViewProviderOrigin* origin;
origin = static_cast<ViewProviderOrigin*>(Gui::Application::Instance->getViewProvider(app_origin[0]));
origin->setTemporaryVisibility(true, false);
}
try {
App::Origin *origin = part->getOrigin();
ViewProviderOrigin* vpOrigin;
vpOrigin = static_cast<ViewProviderOrigin*>(Gui::Application::Instance->getViewProvider(origin));
vpOrigin->setTemporaryVisibility(true, false);
} catch (const Base::Exception &ex) {
Base::Console().Error ("%s\n", ex.what () );
}
}
}
@@ -217,29 +219,20 @@ void TaskPolarPatternParameters::onSelectionChanged(const Gui::SelectionChanges&
else
removeItemFromListWidget(ui->listWidgetFeatures, msg.pObjectName);
exitSelectionMode();
} else if (selectionMode == reference) {
// Note: ReferenceSelection has already checked the selection for validity
} else {
// TODO checkme (2015-09-01, Fat-Zer)
exitSelectionMode();
std::vector<std::string> axes;
App::DocumentObject* selObj;
PartDesign::PolarPattern* pcPolarPattern = static_cast<PartDesign::PolarPattern*>(getObject());
getReferencedSelection(pcPolarPattern, msg, selObj, axes);
pcPolarPattern->Axis.setValue(selObj, axes);
// Note: ReferenceSelection has already checked the selection for validity
if ( selectionMode == reference || selObj->isDerivedFrom ( App::Line::getClassTypeId () ) ) {
pcPolarPattern->Axis.setValue(selObj, axes);
recomputeFeature();
updateUI();
} else if( strstr(msg.pObjectName, App::Part::BaselineTypes[0]) == nullptr ||
strstr(msg.pObjectName, App::Part::BaselineTypes[1]) == nullptr ||
strstr(msg.pObjectName, App::Part::BaselineTypes[2]) == nullptr) {
std::vector<std::string> axes;
App::DocumentObject* selObj;
PartDesign::PolarPattern* pcPolarPattern = static_cast<PartDesign::PolarPattern*>(getObject());
getReferencedSelection(pcPolarPattern, msg, selObj, axes);
pcPolarPattern->Axis.setValue(selObj, axes);
recomputeFeature();
updateUI();
recomputeFeature();
updateUI();
}
}
}
}
@@ -361,12 +354,14 @@ TaskPolarPatternParameters::~TaskPolarPatternParameters()
//hide the parts coordinate system axis for selection
App::Part* part = getPartFor(getObject(), false);
if(part) {
auto app_origin = part->getObjectsOfType(App::Origin::getClassTypeId());
if(!app_origin.empty()) {
ViewProviderOrigin* origin;
origin = static_cast<ViewProviderOrigin*>(Gui::Application::Instance->activeDocument()->getViewProvider(app_origin[0]));
origin->resetTemporaryVisibility();
}
try {
App::Origin *origin = part->getOrigin();
ViewProviderOrigin* vpOrigin;
vpOrigin = static_cast<ViewProviderOrigin*>(Gui::Application::Instance->getViewProvider(origin));
vpOrigin->resetTemporaryVisibility ();
} catch (const Base::Exception &ex) {
Base::Console().Error ("%s\n", ex.what () );
}
}
delete ui;

View File

@@ -133,12 +133,14 @@ TaskRevolutionParameters::TaskRevolutionParameters(PartDesignGui::ViewProvider*
//show the parts coordinate system axis for selection
App::Part* part = getPartFor(vp->getObject(), false);
if(part) {
auto app_origin = part->getObjectsOfType(App::Origin::getClassTypeId());
if(!app_origin.empty()) {
ViewProviderOrigin* origin;
origin = static_cast<ViewProviderOrigin*>(Gui::Application::Instance->getViewProvider(app_origin[0]));
origin->setTemporaryVisibility(true, false);
}
try {
App::Origin *origin = part->getOrigin();
ViewProviderOrigin* vpOrigin;
vpOrigin = static_cast<ViewProviderOrigin*>(Gui::Application::Instance->getViewProvider(origin));
vpOrigin->setTemporaryVisibility(true, false);
} catch (const Base::Exception &ex) {
Base::Console().Error ("%s\n", ex.what () );
}
}
}
@@ -179,9 +181,7 @@ void TaskRevolutionParameters::fillAxisCombo(bool forceRefill)
if (part) {
try {
std::vector<App::DocumentObject*> origs = part->getObjectsOfType(App::Origin::getClassTypeId());
App::Origin* orig = static_cast<App::Origin*>(origs[0]);
App::Origin* orig = part->getOrigin();
addAxisToCombo(orig->getX(),"",tr("Base X axis"));
addAxisToCombo(orig->getY(),"",tr("Base Y axis"));
addAxisToCombo(orig->getZ(),"",tr("Base Z axis"));
@@ -362,14 +362,16 @@ TaskRevolutionParameters::~TaskRevolutionParameters()
//hide the parts coordinate system axis for selection
App::Part* part = getPartFor(vp->getObject(), false);
if(part) {
auto app_origin = part->getObjectsOfType(App::Origin::getClassTypeId());
if(!app_origin.empty()) {
ViewProviderOrigin* origin;
origin = static_cast<ViewProviderOrigin*>(Gui::Application::Instance->getViewProvider(app_origin[0]));
origin->resetTemporaryVisibility();
}
try {
App::Origin *origin = part->getOrigin();
ViewProviderOrigin* vpOrigin;
vpOrigin = static_cast<ViewProviderOrigin*>(Gui::Application::Instance->getViewProvider(origin));
vpOrigin->resetTemporaryVisibility();
} catch (const Base::Exception &ex) {
Base::Console().Error ("%s\n", ex.what () );
}
}
delete ui;
for(int i = 0 ; i < axesInList.size() ; i++ ){

View File

@@ -196,9 +196,7 @@ void TaskTransformedParameters::fillAxisCombo(ComboLinks &combolinks,
if (part) {
try {
std::vector<App::DocumentObject*> origs = part->getObjectsOfType(App::Origin::getClassTypeId());
App::Origin* orig = static_cast<App::Origin*>(origs[0]);
App::Origin* orig = part->getOrigin();
combolinks.addLink(orig->getX(),"",tr("Base X axis"));
combolinks.addLink(orig->getY(),"",tr("Base Y axis"));
combolinks.addLink(orig->getZ(),"",tr("Base Z axis"));
@@ -234,9 +232,7 @@ void TaskTransformedParameters::fillPlanesCombo(ComboLinks &combolinks,
if (part) {
try {
std::vector<App::DocumentObject*> origs = part->getObjectsOfType(App::Origin::getClassTypeId());
App::Origin* orig = static_cast<App::Origin*>(origs[0]);
App::Origin* orig = part->getOrigin();
combolinks.addLink(orig->getXY(),"",tr("Base XY plane"));
combolinks.addLink(orig->getYZ(),"",tr("Base YZ plane"));
combolinks.addLink(orig->getXZ(),"",tr("Base XZ plane"));

View File

@@ -29,6 +29,8 @@
#endif
#include <App/Part.h>
#include <App/Origin.h>
#include <App/OriginFeature.h>
#include <App/DocumentObjectGroup.h>
#include <Gui/Application.h>
#include <Gui/Command.h>
@@ -132,27 +134,6 @@ static void buildDefaultPartAndBody(const App::Document* doc)
Gui::Command::doCommand(Gui::Command::Gui, "Gui.activeView().setActiveObject('Part',App.activeDocument().%s)", PartName.c_str());
}
PartDesign::Body *setUpPart(const App::Part *part)
{
// first do the general Part setup
Gui::ViewProviderPart::setUpPart(part);
// check for Bodies
// std::vector<App::DocumentObject*> bodies = part->getObjectsOfType(PartDesign::Body::getClassTypeId());
// assert(bodies.size() == 0);
// std::string PartName = part->getNameInDocument();
// std::string BodyName = part->getDocument()->getUniqueObjectName("MainBody");
Gui::Command::addModule(Gui::Command::Doc, "PartDesign");
// Gui::Command::doCommand(Gui::Command::Doc, "App.activeDocument().addObject('PartDesign::Body','%s')", BodyName.c_str());
// Gui::Command::doCommand(Gui::Command::Doc, "App.activeDocument().%s.addObject(App.activeDocument().ActiveObject)", part->getNameInDocument());
// Gui::Command::doCommand(Gui::Command::Gui, "Gui.activeView().setActiveObject('%s', App.activeDocument().%s)", PDBODYKEY, BodyName.c_str());
Gui::Command::updateActive();
return NULL;
}
void fixSketchSupport (Sketcher::SketchObject* sketch)
{
@@ -163,11 +144,17 @@ void fixSketchSupport (Sketcher::SketchObject* sketch)
const App::Document* doc = sketch->getDocument();
PartDesign::Body *body = getBodyFor(sketch, /*messageIfNot*/ 0);
if (!body) {
throw Base::Exception ("Coudn't find body for the sketch");
}
// Get the Origin for the body
App::OriginGroup *grp = App::OriginGroup::getGroupOfObject (body);
if (!grp) {
throw Base::Exception ("Coudn't find group for body");
}
App::Origin *origin = grp->getOrigin (); // May throw by itself
Base::Placement plm = sketch->Placement.getValue();
Base::Vector3d pnt = plm.getPosition();
@@ -177,17 +164,19 @@ void fixSketchSupport (Sketcher::SketchObject* sketch)
rot.multVec(sketchVector, sketchVector);
bool reverseSketch = (sketchVector.x + sketchVector.y + sketchVector.z) < 0.0 ;
if (reverseSketch) sketchVector *= -1.0;
int index;
App::Plane *plane =0;
if (sketchVector == Base::Vector3d(0,0,1))
index = 0;
plane = origin->getXY ();
else if (sketchVector == Base::Vector3d(0,1,0))
index = 1;
plane = origin->getXZ ();
else if (sketchVector == Base::Vector3d(1,0,0))
index = 2;
plane = origin->getYZ ();
else {
throw Base::Exception("Sketch plane cannot be migrated");
}
assert (plane);
// Find the normal distance from origin to the sketch plane
gp_Pln pln(gp_Pnt (pnt.x, pnt.y, pnt.z), gp_Dir(sketchVector.x, sketchVector.y, sketchVector.z));
@@ -197,7 +186,7 @@ void fixSketchSupport (Sketcher::SketchObject* sketch)
if (fabs(offset) < Precision::Confusion()) {
// One of the base planes
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.Support = (App.activeDocument().%s,[''])",
sketch->getNameInDocument(), App::Part::BaseplaneTypes[index]);
sketch->getNameInDocument(), plane->getNameInDocument () );
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.MapReversed = %s",
sketch->getNameInDocument(), reverseSketch ? "True" : "False");
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.MapMode = '%s'",
@@ -211,16 +200,21 @@ void fixSketchSupport (Sketcher::SketchObject* sketch)
offset *= -1.0;
std::string Datum = doc->getUniqueObjectName("DatumPlane");
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().addObject('PartDesign::Plane','%s')",Datum.c_str());
QString refStr = QString::fromAscii("[(App.activeDocument().") + QString::fromAscii(App::Part::BaseplaneTypes[index]) +
QString::fromAscii(",'')]");
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.Support = %s",Datum.c_str(), refStr.toStdString().c_str());
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.MapMode = '%s'",Datum.c_str(), AttachEngine::eMapModeStrings[Attacher::mmFlatFace]);
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.superPlacement.Base.z = %f",Datum.c_str(), offset);
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().addObject('PartDesign::Plane','%s')",
Datum.c_str());
QString refStr = QString::fromAscii("[(App.activeDocument().%1,'')]")
.arg ( QString::fromAscii ( plane->getNameInDocument () ) );
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.Support = %s",
Datum.c_str(), refStr.toStdString().c_str());
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.MapMode = '%s'",
Datum.c_str(), AttachEngine::eMapModeStrings[Attacher::mmFlatFace]);
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.superPlacement.Base.z = %f",
Datum.c_str(), offset);
Gui::Command::doCommand(Gui::Command::Doc,
"App.activeDocument().%s.insertFeature(App.activeDocument().%s, App.activeDocument().%s)",
body->getNameInDocument(), Datum.c_str(), sketch->getNameInDocument());
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.Support = (App.activeDocument().%s,[''])",
Gui::Command::doCommand(Gui::Command::Doc,
"App.activeDocument().%s.Support = (App.activeDocument().%s,[''])",
sketch->getNameInDocument(), Datum.c_str());
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.MapReversed = %s",
sketch->getNameInDocument(), reverseSketch ? "True" : "False");

View File

@@ -51,17 +51,6 @@ PartDesign::Body *getBody(bool messageIfNot);
PartDesign::Body *getBodyFor(const App::DocumentObject*, bool messageIfNot);
App::Part *getPartFor(const App::DocumentObject*, bool messageIfNot);
/** Setup a Part for PartDesign
* This methode is use to populate a Part object with all
* necesarry PartDesign and base objects to allow the use
* in PartDesign. Its called from within PartDesign as well
* as from other modules which wish to set up a Part for PartDesin
* (e.g. Assembly):
* TODO any reasons why this should return a value? (2015-08-08, Fat-Zer)
*/
PartDesign::Body *setUpPart(const App::Part *);
/// Fix sketch support after moving a free sketch into a body
void fixSketchSupport(Sketcher::SketchObject* sketch);