fix dependent copy references
to make them work with sketches an additional Part2DObject reference needed to be created
This commit is contained in:
@@ -60,6 +60,7 @@
|
||||
#include "ViewProviderThickness.h"
|
||||
#include "ViewProviderPipe.h"
|
||||
#include "ViewProviderLoft.h"
|
||||
#include "ViewProviderShapeBinder.h"
|
||||
|
||||
// use a different name to CreateCommand()
|
||||
void CreatePartDesignCommands(void);
|
||||
@@ -144,6 +145,7 @@ PyMODINIT_FUNC initPartDesignGui()
|
||||
PartDesignGui::ViewProviderDatumLine ::init();
|
||||
PartDesignGui::ViewProviderDatumPlane ::init();
|
||||
PartDesignGui::ViewProviderDatumCoordinateSystem::init();
|
||||
PartDesignGui::ViewProviderShapeBinder ::init();
|
||||
PartDesignGui::ViewProviderBoolean ::init();
|
||||
PartDesignGui::ViewProviderAddSub ::init();
|
||||
PartDesignGui::ViewProviderPrimitive ::init();
|
||||
|
||||
@@ -133,6 +133,8 @@ SET(PartDesignGuiViewProvider_SRCS
|
||||
ViewProviderDatumPlane.h
|
||||
ViewProviderDatumCS.cpp
|
||||
ViewProviderDatumCS.h
|
||||
ViewProviderShapeBinder.h
|
||||
ViewProviderShapeBinder.cpp
|
||||
ViewProviderBoolean.cpp
|
||||
ViewProviderBoolean.h
|
||||
ViewProviderAddSub.cpp
|
||||
|
||||
@@ -667,7 +667,7 @@ void prepareSketchBased(Gui::Command* cmd, const std::string& which,
|
||||
// If there is more than one selection/possibility, show dialog and let user pick sketch
|
||||
if ((bNoSketchWasSelected && validSketches > 1) ||
|
||||
(!bNoSketchWasSelected && sketches.size() > 1) ||
|
||||
ext ) {
|
||||
(!bNoSketchWasSelected && ext) ) {
|
||||
|
||||
Gui::TaskView::TaskDialog *dlg = Gui::Control().activeDialog();
|
||||
PartDesignGui::TaskDlgFeaturePick *pickDlg = qobject_cast<PartDesignGui::TaskDlgFeaturePick *>(dlg);
|
||||
@@ -689,7 +689,7 @@ void prepareSketchBased(Gui::Command* cmd, const std::string& which,
|
||||
|
||||
Gui::Selection().clearSelection();
|
||||
pickDlg = new PartDesignGui::TaskDlgFeaturePick(sketches, status, accepter, worker);
|
||||
if(ext)
|
||||
if(!bNoSketchWasSelected && ext)
|
||||
pickDlg->showExternal(true);
|
||||
|
||||
Gui::Control().showDialog(pickDlg);
|
||||
|
||||
@@ -45,6 +45,11 @@
|
||||
|
||||
#include "ui_TaskFeaturePick.h"
|
||||
#include "TaskFeaturePick.h"
|
||||
#include <Mod/PartDesign/App/ShapeBinder.h>
|
||||
#include <Mod/PartDesign/App/DatumPoint.h>
|
||||
#include <Mod/PartDesign/App/DatumLine.h>
|
||||
#include <Mod/PartDesign/App/DatumPlane.h>
|
||||
#include <Mod/Part/App/DatumFeature.h>
|
||||
|
||||
using namespace PartDesignGui;
|
||||
|
||||
@@ -266,50 +271,83 @@ std::vector<App::DocumentObject*> TaskFeaturePick::buildFeatures() {
|
||||
}
|
||||
|
||||
App::DocumentObject* TaskFeaturePick::makeCopy(App::DocumentObject* obj, bool independent) {
|
||||
App::DocumentObject* copy = nullptr;
|
||||
if(independent) {
|
||||
|
||||
//we do know that the created instance is a document object, as obj is one. But we do not know which
|
||||
//exact type
|
||||
auto name = std::string("Copy") + std::string(obj->getNameInDocument());
|
||||
copy = App::GetApplication().getActiveDocument()->addObject(obj->getTypeId().getName(), name.c_str());
|
||||
|
||||
//we do know that the created instance is a document object, as obj is one. But we do not know which
|
||||
//exact type
|
||||
auto name = std::string("Copy") + std::string(obj->getNameInDocument());
|
||||
auto copy = App::GetApplication().getActiveDocument()->addObject(obj->getTypeId().getName(), name.c_str());
|
||||
|
||||
if(copy) {
|
||||
//copy over all properties
|
||||
std::vector<App::Property*> props;
|
||||
std::vector<App::Property*> cprops;
|
||||
obj->getPropertyList(props);
|
||||
copy->getPropertyList(cprops);
|
||||
try{
|
||||
auto it = cprops.begin();
|
||||
for( App::Property* prop : props ) {
|
||||
|
||||
//independent copys dont have links and are not attached
|
||||
if(independent && (
|
||||
prop->getTypeId() == App::PropertyLink::getClassTypeId() ||
|
||||
prop->getTypeId() == App::PropertyLinkList::getClassTypeId() ||
|
||||
prop->getTypeId() == App::PropertyLinkSub::getClassTypeId() ||
|
||||
prop->getTypeId() == App::PropertyLinkSubList::getClassTypeId()||
|
||||
( prop->getGroup() && strcmp(prop->getGroup(),"Attachment")==0) )) {
|
||||
|
||||
++it;
|
||||
continue;
|
||||
}
|
||||
|
||||
App::Property* cprop = *it++;
|
||||
|
||||
if( strcmp(prop->getName(), "Label") == 0 ) {
|
||||
static_cast<App::PropertyString*>(cprop)->setValue("wuhahahahah");
|
||||
continue;
|
||||
}
|
||||
|
||||
cprop->Paste(*prop);
|
||||
}
|
||||
}
|
||||
catch(const Base::Exception& e) {
|
||||
|
||||
Base::Console().Message("Exception: %s\n", e.what());
|
||||
copy->getPropertyList(cprops);
|
||||
|
||||
auto it = cprops.begin();
|
||||
for( App::Property* prop : props ) {
|
||||
|
||||
//independent copys dont have links and are not attached
|
||||
if(independent && (
|
||||
prop->getTypeId() == App::PropertyLink::getClassTypeId() ||
|
||||
prop->getTypeId() == App::PropertyLinkList::getClassTypeId() ||
|
||||
prop->getTypeId() == App::PropertyLinkSub::getClassTypeId() ||
|
||||
prop->getTypeId() == App::PropertyLinkSubList::getClassTypeId()||
|
||||
( prop->getGroup() && strcmp(prop->getGroup(),"Attachment")==0) )) {
|
||||
|
||||
++it;
|
||||
continue;
|
||||
}
|
||||
|
||||
App::Property* cprop = *it++;
|
||||
|
||||
if( strcmp(prop->getName(), "Label") == 0 ) {
|
||||
static_cast<App::PropertyString*>(cprop)->setValue(name.c_str());
|
||||
continue;
|
||||
}
|
||||
|
||||
cprop->Paste(*prop);
|
||||
}
|
||||
}
|
||||
|
||||
else {
|
||||
|
||||
auto name = std::string("Reference") + std::string(obj->getNameInDocument());
|
||||
|
||||
// TODO Replace it with commands (2015-09-11, Fat-Zer)
|
||||
if(obj->isDerivedFrom(Part::Datum::getClassTypeId())) {
|
||||
copy = App::GetApplication().getActiveDocument()->addObject(
|
||||
obj->getClassTypeId().getName(), name.c_str() );
|
||||
|
||||
//we need to reference the individual datums and make again datums. This is important as
|
||||
//datum adjust their size dependend on the part size, hence simply copying the shape is
|
||||
//not enough
|
||||
Part::Datum *datumCopy = static_cast<Part::Datum*>(copy);
|
||||
datumCopy->Support.setValue(obj, "");
|
||||
|
||||
if(obj->getTypeId() == PartDesign::Point::getClassTypeId()) {
|
||||
datumCopy->MapMode.setValue(mm0Vertex);
|
||||
}
|
||||
else if(obj->getTypeId() == PartDesign::Line::getClassTypeId()) {
|
||||
datumCopy->MapMode.setValue(mm1TwoPoints);
|
||||
}
|
||||
else if(obj->getTypeId() == PartDesign::Plane::getClassTypeId()) {
|
||||
datumCopy->MapMode.setValue(mmFlatFace);
|
||||
}
|
||||
}
|
||||
else if(obj->isDerivedFrom(Part::Part2DObject::getClassTypeId()) ||
|
||||
obj->getTypeId() == PartDesign::ShapeBinder2D::getClassTypeId()) {
|
||||
copy = App::GetApplication().getActiveDocument()->addObject("PartDesign::ShapeBinder2D", name.c_str());
|
||||
static_cast<PartDesign::ShapeBinder2D*>(copy)->Support.setValue(obj, "");
|
||||
}
|
||||
else if(obj->getTypeId() == PartDesign::ShapeBinder::getClassTypeId() ||
|
||||
obj->isDerivedFrom(Part::Feature::getClassTypeId())) {
|
||||
|
||||
copy = App::GetApplication().getActiveDocument()->addObject("PartDesign::ShapeBinder", name.c_str());
|
||||
static_cast<PartDesign::ShapeBinder*>(copy)->Support.setValue(obj, "");
|
||||
}
|
||||
}
|
||||
|
||||
return copy;
|
||||
}
|
||||
|
||||
|
||||
54
src/Mod/PartDesign/Gui/ViewProviderShapeBinder.cpp
Normal file
54
src/Mod/PartDesign/Gui/ViewProviderShapeBinder.cpp
Normal file
@@ -0,0 +1,54 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2015 Stefan Tröger <stefantroeger@gmx.net> *
|
||||
* *
|
||||
* This file is part of the FreeCAD CAx development system. *
|
||||
* *
|
||||
* This library is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU Library General Public *
|
||||
* License as published by the Free Software Foundation; either *
|
||||
* version 2 of the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This library is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU Library General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Library General Public *
|
||||
* License along with this library; see the file COPYING.LIB. If not, *
|
||||
* write to the Free Software Foundation, Inc., 59 Temple Place, *
|
||||
* Suite 330, Boston, MA 02111-1307, USA *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
#include "PreCompiled.h"
|
||||
|
||||
#ifndef _PreComp_
|
||||
# include <Inventor/nodes/SoSeparator.h>
|
||||
#endif
|
||||
|
||||
#include <Mod/PartDesign/App/ShapeBinder.h>
|
||||
|
||||
#include "ViewProviderShapeBinder.h"
|
||||
|
||||
using namespace PartDesignGui;
|
||||
|
||||
PROPERTY_SOURCE(PartDesignGui::ViewProviderShapeBinder,PartGui::ViewProviderPart)
|
||||
|
||||
ViewProviderShapeBinder::ViewProviderShapeBinder()
|
||||
{
|
||||
sPixmap = "PartDesign_ShapeBinder.svg";
|
||||
}
|
||||
|
||||
ViewProviderShapeBinder::~ViewProviderShapeBinder()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool ViewProviderShapeBinder::setEdit(int ModNum) {
|
||||
return true;//PartGui::ViewProviderPartExt::setEdit(ModNum);
|
||||
}
|
||||
|
||||
void ViewProviderShapeBinder::unsetEdit(int ModNum) {
|
||||
return;//PartGui::ViewProviderPartExt::unsetEdit(ModNum);
|
||||
}
|
||||
50
src/Mod/PartDesign/Gui/ViewProviderShapeBinder.h
Normal file
50
src/Mod/PartDesign/Gui/ViewProviderShapeBinder.h
Normal file
@@ -0,0 +1,50 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2015 Stefan Tröger <stefantroeger@gmx.net> *
|
||||
* *
|
||||
* This file is part of the FreeCAD CAx development system. *
|
||||
* *
|
||||
* This library is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU Library General Public *
|
||||
* License as published by the Free Software Foundation; either *
|
||||
* version 2 of the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This library is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU Library General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Library General Public *
|
||||
* License along with this library; see the file COPYING.LIB. If not, *
|
||||
* write to the Free Software Foundation, Inc., 59 Temple Place, *
|
||||
* Suite 330, Boston, MA 02111-1307, USA *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
#ifndef PARTGUI_ViewProviderShapeBinder_H
|
||||
#define PARTGUI_ViewProviderShapeBinder_H
|
||||
|
||||
#include <Mod/Part/Gui/ViewProvider.h>
|
||||
|
||||
namespace PartDesignGui {
|
||||
|
||||
// TODO may be derive from something else e.g. ViewProviderGeometryObject (2015-09-11, Fat-Zer)
|
||||
class PartDesignGuiExport ViewProviderShapeBinder : public PartGui::ViewProviderPart
|
||||
{
|
||||
PROPERTY_HEADER(PartDesignGui::ViewProviderShapeBinder);
|
||||
|
||||
public:
|
||||
/// Constructor
|
||||
ViewProviderShapeBinder();
|
||||
virtual ~ViewProviderShapeBinder();
|
||||
|
||||
protected:
|
||||
virtual bool setEdit(int ModNum);
|
||||
virtual void unsetEdit(int ModNum);
|
||||
|
||||
};
|
||||
|
||||
} // namespace PartDesignGui
|
||||
|
||||
|
||||
#endif // PARTGUI_ViewProviderShapeBinder_H
|
||||
Reference in New Issue
Block a user