Merge branch 'master' of github.com:FreeCAD/FreeCAD

This commit is contained in:
Yorik van Havre
2020-04-14 16:52:33 +02:00
8 changed files with 123 additions and 47 deletions

View File

@@ -37,6 +37,7 @@
#include <App/Application.h>
#include <App/Document.h>
#include <App/DocumentObject.h>
#include <App/Part.h>
#include <Base/BoundBox.h>
#include <Base/Console.h>
@@ -73,6 +74,7 @@ DrawProjGroup::DrawProjGroup(void) :
ADD_PROPERTY_TYPE(Source ,(0), group, App::Prop_None,"Shape to view");
Source.setScope(App::LinkScope::Global);
Source.setAllowExternal(true);
ADD_PROPERTY_TYPE(XSource ,(0),group,App::Prop_None,"External 3D Shape to view");
ADD_PROPERTY_TYPE(Anchor, (0), group, App::Prop_None, "The root view to align projections with");
Anchor.setScope(App::LinkScope::Global);
@@ -93,15 +95,28 @@ DrawProjGroup::~DrawProjGroup()
{
}
//TODO: this duplicates code in DVP
std::vector<App::DocumentObject*> DrawProjGroup::getAllSources(void) const
{
// Base::Console().Message("DPG::getAllSources()\n");
const std::vector<App::DocumentObject*> links = Source.getValues();
std::vector<DocumentObject*> xLinks;
XSource.getLinks(xLinks);
std::vector<App::DocumentObject*> result = links;
if (!xLinks.empty()) {
result.insert(result.end(), xLinks.begin(), xLinks.end());
}
return result;
}
void DrawProjGroup::onChanged(const App::Property* prop)
{
//TODO: For some reason, when the projection type is changed, the isometric views show change appropriately, but the orthographic ones don't... Or vice-versa. WF: why would you change from 1st to 3rd in mid drawing?
//if group hasn't been added to page yet, can't scale or distribute projItems
TechDraw::DrawPage *page = getPage();
if (!isRestoring() && page) {
if (prop == &Source) {
//nothing in particular
}
if (prop == &Scale) {
if (!m_lockScale) {
updateChildrenScale();
@@ -112,7 +127,8 @@ void DrawProjGroup::onChanged(const App::Property* prop)
updateChildrenEnforce();
}
if (prop == &Source) {
if ( (prop == &Source) ||
(prop == &XSource) ) {
updateChildrenSource();
}
@@ -156,7 +172,7 @@ App::DocumentObjectExecReturn *DrawProjGroup::execute(void)
return DrawViewCollection::execute();
}
std::vector<App::DocumentObject*> docObjs = Source.getValues();
std::vector<App::DocumentObject*> docObjs = getAllSources();
if (docObjs.empty()) {
return DrawViewCollection::execute();
}
@@ -188,6 +204,7 @@ short DrawProjGroup::mustExecute() const
if (!isRestoring()) {
result = Views.isTouched() ||
Source.isTouched() ||
XSource.isTouched() ||
Scale.isTouched() ||
ScaleType.isTouched() ||
ProjectionType.isTouched() ||
@@ -428,6 +445,11 @@ App::DocumentObject * DrawProjGroup::addProjection(const char *viewProjType)
view->Label.setValue(viewProjType);
addView(view); //from DrawViewCollection
view->Source.setValues(Source.getValues());
// std::vector<DocumentObject*> xLinks;
// XSource.getLinks(xLinks);
// view->XSource.setValues(xLinks);
view->XSource.setValues(XSource.getValues());
// the Scale is already set by DrawView
view->Type.setValue(viewProjType);
if (strcmp(viewProjType, "Front") != 0 ) { //not Front!
@@ -957,8 +979,13 @@ void DrawProjGroup::updateChildrenSource(void)
Base::Console().Log("PROBLEM - DPG::updateChildrenSource - non DPGI entry in Views! %s\n",
getNameInDocument());
throw Base::TypeError("Error: projection in DPG list is not a DPGI!");
} else if (view->Source.getValues() != Source.getValues()) {
view->Source.setValues(Source.getValues());
} else {
if (view->Source.getValues() != Source.getValues()) {
view->Source.setValues(Source.getValues());
}
if (view->XSource.getValues() != XSource.getValues()) {
view->XSource.setValues(XSource.getValues());
}
}
}
}

View File

@@ -27,6 +27,8 @@
# include <QRectF>
#include <App/DocumentObject.h>
#include <App/PropertyStandard.h>
#include <App/PropertyLinks.h>
#include <Base/BoundBox.h>
#include <Base/Matrix.h>
@@ -55,7 +57,9 @@ public:
DrawProjGroup();
~DrawProjGroup();
App::PropertyLinkList Source;
App::PropertyLinkList Source;
App::PropertyXLinkList XSource;
App::PropertyEnumeration ProjectionType;
App::PropertyBool AutoDistribute;
@@ -134,6 +138,9 @@ public:
void autoPositionChildren(void);
void updateChildrenEnforce(void);
std::vector<App::DocumentObject*> getAllSources(void) const;
protected:
void onChanged(const App::Property* prop) override;

View File

@@ -86,6 +86,7 @@ short DrawProjGroupItem::mustExecute() const
result = (Direction.isTouched() ||
XDirection.isTouched() ||
Source.isTouched() ||
XSource.isTouched() ||
Scale.isTouched());
}
@@ -174,6 +175,7 @@ void DrawProjGroupItem::autoPosition()
void DrawProjGroupItem::onDocumentRestored()
{
// Base::Console().Message("DPGI::onDocumentRestored() - %s\n", getNameInDocument());
App::DocumentObjectExecReturn* rc = DrawProjGroupItem::execute();
if (rc) {
delete rc;

View File

@@ -143,6 +143,8 @@ DrawViewPart::DrawViewPart(void) :
ADD_PROPERTY_TYPE(Source ,(0),group,App::Prop_None,"3D Shape to view");
Source.setScope(App::LinkScope::Global);
Source.setAllowExternal(true);
ADD_PROPERTY_TYPE(XSource ,(0),group,App::Prop_None,"External 3D Shape to view");
ADD_PROPERTY_TYPE(Direction ,(0.0,-1.0,0.0),
group,App::Prop_None,"Projection Plane normal. The direction you are looking from.");
@@ -181,7 +183,7 @@ std::vector<TopoDS_Shape> DrawViewPart::getSourceShape2d(void) const
{
// Base::Console().Message("DVP::getSourceShape2d()\n");
std::vector<TopoDS_Shape> result;
const std::vector<App::DocumentObject*>& links = Source.getValues();
const std::vector<App::DocumentObject*>& links = getAllSources();
result = ShapeExtractor::getShapes2d(links);
return result;
}
@@ -189,8 +191,9 @@ std::vector<TopoDS_Shape> DrawViewPart::getSourceShape2d(void) const
TopoDS_Shape DrawViewPart::getSourceShape(void) const
{
// Base::Console().Message("DVP::getSourceShape()\n");
TopoDS_Shape result;
const std::vector<App::DocumentObject*>& links = Source.getValues();
const std::vector<App::DocumentObject*>& links = getAllSources();
if (links.empty()) {
bool isRestoring = getDocument()->testStatus(App::Document::Status::Restoring);
if (isRestoring) {
@@ -208,8 +211,10 @@ TopoDS_Shape DrawViewPart::getSourceShape(void) const
TopoDS_Shape DrawViewPart::getSourceShapeFused(void) const
{
// Base::Console().Message("DVP::getSourceShapeFused()\n");
TopoDS_Shape result;
const std::vector<App::DocumentObject*>& links = Source.getValues();
// const std::vector<App::DocumentObject*>& links = Source.getValues();
const std::vector<App::DocumentObject*>& links = getAllSources();
if (links.empty()) {
bool isRestoring = getDocument()->testStatus(App::Document::Status::Restoring);
if (isRestoring) {
@@ -225,6 +230,20 @@ TopoDS_Shape DrawViewPart::getSourceShapeFused(void) const
return result;
}
std::vector<App::DocumentObject*> DrawViewPart::getAllSources(void) const
{
// Base::Console().Message("DVP::getAllSources()\n");
const std::vector<App::DocumentObject*> links = Source.getValues();
std::vector<DocumentObject*> xLinks = XSource.getValues();
// std::vector<DocumentObject*> xLinks;
// XSource.getLinks(xLinks);
std::vector<App::DocumentObject*> result = links;
if (!xLinks.empty()) {
result.insert(result.end(), xLinks.begin(), xLinks.end());
}
return result;
}
App::DocumentObjectExecReturn *DrawViewPart::execute(void)
{
@@ -232,10 +251,13 @@ App::DocumentObjectExecReturn *DrawViewPart::execute(void)
if (!keepUpdated()) {
return App::DocumentObject::StdReturn;
}
// Base::Console().Message("DVP::execute - Source: %d XSource: %d\n",
// Source.getValues().size(), XSource.getValues().size());
App::Document* doc = getDocument();
bool isRestoring = doc->testStatus(App::Document::Status::Restoring);
const std::vector<App::DocumentObject*>& links = Source.getValues();
const std::vector<App::DocumentObject*>& links = getAllSources();
if (links.empty()) {
if (isRestoring) {
Base::Console().Warning("DVP::execute - No Sources (but document is restoring) - %s\n",
@@ -246,7 +268,6 @@ App::DocumentObjectExecReturn *DrawViewPart::execute(void)
}
return App::DocumentObject::StdReturn;
}
std::vector<App::DocumentObject*> sources = Source.getValues();
TopoDS_Shape shape = getSourceShape();
if (shape.IsNull()) {
@@ -307,6 +328,7 @@ short DrawViewPart::mustExecute() const
if (!isRestoring()) {
result = (Direction.isTouched() ||
Source.isTouched() ||
XSource.isTouched() ||
Perspective.isTouched() ||
Focus.isTouched() ||
Rotation.isTouched() ||

View File

@@ -93,6 +93,7 @@ public:
virtual ~DrawViewPart();
App::PropertyLinkList Source;
App::PropertyXLinkList XSource;
App::PropertyVector Direction; //TODO: Rename to YAxisDirection or whatever this actually is (ProjectionDirection)
App::PropertyVector XDirection;
App::PropertyBool Perspective;
@@ -202,6 +203,9 @@ public:
void removeAllReferencesFromGeom();
void resetReferenceVerts();
std::vector<App::DocumentObject*> getAllSources(void) const;
protected:
bool checkXDirection(void) const;

View File

@@ -30,28 +30,30 @@
#include <vector>
#include <Base/Exception.h>
#include <Base/Tools.h>
#include <Base/PyObjectBase.h>
#include <App/Application.h>
#include <App/Document.h>
#include <App/DocumentObject.h>
#include <App/DocumentObjectGroup.h>
#include <App/DocumentObject.h>
#include <App/FeaturePython.h>
#include <App/PropertyGeo.h>
#include <App/GeoFeature.h>
#include <App/Link.h>
#include <App/PropertyGeo.h>
#include <App/PropertyLinks.h>
#include <Base/Console.h>
#include <Base/Exception.h>
#include <Base/Exception.h>
#include <Base/Parameter.h>
#include <Base/PyObjectBase.h>
#include <Base/Tools.h>
#include <Gui/Action.h>
#include <Gui/Application.h>
#include <Gui/BitmapFactory.h>
#include <Gui/Command.h>
#include <Gui/Control.h>
#include <Gui/Document.h>
#include <Gui/Selection.h>
#include <Gui/MainWindow.h>
#include <Gui/FileDialog.h>
#include <Gui/MainWindow.h>
#include <Gui/Selection.h>
#include <Gui/ViewProvider.h>
#include <Gui/WaitCursor.h>
@@ -304,6 +306,7 @@ void CmdTechDrawView::activated(int iMsg)
//set projection direction from selected Face
//use first object with a face selected
std::vector<App::DocumentObject*> shapes;
std::vector<App::DocumentObject*> xShapes;
App::DocumentObject* partObj = nullptr;
std::string faceName;
int resolve = 1; //mystery
@@ -317,22 +320,33 @@ void CmdTechDrawView::activated(int iMsg)
if (obj->isDerivedFrom(TechDraw::DrawPage::getClassTypeId()) ) {
continue;
}
if ( obj->isDerivedFrom(App::LinkElement::getClassTypeId()) ||
obj->isDerivedFrom(App::LinkGroup::getClassTypeId()) ||
obj->isDerivedFrom(App::Link::getClassTypeId()) ) {
xShapes.push_back(obj);
continue;
}
//not a Link and not null. assume to be drawable. Undrawables will be
// skipped later.
if (obj != nullptr) {
shapes.push_back(obj);
}
if(partObj != nullptr) {
continue;
}
//don't know if this works for an XLink
for(auto& sub : sel.getSubNames()) {
if (TechDraw::DrawUtil::getGeomTypeFromName(sub) == "Face") {
faceName = sub;
//
partObj = obj;
break;
}
}
}
if ((shapes.empty())) {
if ( shapes.empty() &&
xShapes.empty() ) {
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
QObject::tr("No Shapes, Groups or Links in this selection"));
return;
@@ -350,6 +364,7 @@ void CmdTechDrawView::activated(int iMsg)
throw Base::TypeError("CmdTechDrawView DVP not found\n");
}
dvp->Source.setValues(shapes);
dvp->XSource.setValues(xShapes);
doCommand(Doc,"App.activeDocument().%s.addView(App.activeDocument().%s)",PageName.c_str(),FeatName.c_str());
if (faceName.size()) {
std::pair<Base::Vector3d,Base::Vector3d> dirs = DrawGuiUtil::getProjDirFromFace(partObj,faceName);
@@ -450,26 +465,6 @@ void CmdTechDrawSectionView::activated(int iMsg)
return;
}
TechDraw::DrawViewPart* dvp = static_cast<TechDraw::DrawViewPart*>(*baseObj.begin());
// std::string BaseName = dvp->getNameInDocument();
// std::string PageName = page->getNameInDocument();
// double baseScale = dvp->getScale();
// Gui::WaitCursor wc;
// openCommand("Create view");
// std::string FeatName = getUniqueObjectName("Section");
// doCommand(Doc,"App.activeDocument().addObject('TechDraw::DrawViewSection','%s')",FeatName.c_str());
// App::DocumentObject *docObj = getDocument()->getObject(FeatName.c_str());
// TechDraw::DrawViewSection* dsv = dynamic_cast<TechDraw::DrawViewSection *>(docObj);
// if (!dsv) {
// throw Base::TypeError("CmdTechDrawSectionView DVS not found\n");
// }
// dsv->Source.setValues(dvp->Source.getValues());
// doCommand(Doc,"App.activeDocument().%s.BaseView = App.activeDocument().%s",FeatName.c_str(),BaseName.c_str());
// doCommand(Doc,"App.activeDocument().%s.ScaleType = App.activeDocument().%s.ScaleType",FeatName.c_str(),BaseName.c_str());
// doCommand(Doc,"App.activeDocument().%s.addView(App.activeDocument().%s)",PageName.c_str(),FeatName.c_str());
// doCommand(Doc,"App.activeDocument().%s.Scale = %0.6f",FeatName.c_str(),baseScale);
Gui::Control().showDialog(new TaskDlgSectionView(dvp));
updateActive(); //ok here since dialog doesn't call doc.recompute()
@@ -568,6 +563,7 @@ void CmdTechDrawProjectionGroup::activated(int iMsg)
//set projection direction from selected Face
//use first object with a face selected
std::vector<App::DocumentObject*> shapes;
std::vector<App::DocumentObject*> xShapes;
App::DocumentObject* partObj = nullptr;
std::string faceName;
int resolve = 1; //mystery
@@ -577,14 +573,19 @@ void CmdTechDrawProjectionGroup::activated(int iMsg)
resolve,
single);
for (auto& sel: selection) {
// for(auto &sel : getSelection().getSelectionEx(0,App::DocumentObject::getClassTypeId(),false)) {
auto obj = sel.getObject();
if (obj->isDerivedFrom(TechDraw::DrawPage::getClassTypeId()) ) {
continue;
}
// if(!obj || inlist.count(obj)) //??????
// continue;
if (obj != nullptr) { //can this happen?
if ( obj->isDerivedFrom(App::LinkElement::getClassTypeId()) ||
obj->isDerivedFrom(App::LinkGroup::getClassTypeId()) ||
obj->isDerivedFrom(App::Link::getClassTypeId()) ) {
xShapes.push_back(obj);
continue;
}
//not a Link and not null. assume to be drawable. Undrawables will be
// skipped later.
if (obj != nullptr) {
shapes.push_back(obj);
}
if(partObj != nullptr) {
@@ -598,9 +599,10 @@ void CmdTechDrawProjectionGroup::activated(int iMsg)
}
}
}
if (shapes.empty()) {
if ( shapes.empty() &&
xShapes.empty() ) {
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
QObject::tr("No Shapes or Groups in this selection"));
QObject::tr("No Shapes, Groups or Links in this selection"));
return;
}
@@ -618,6 +620,7 @@ void CmdTechDrawProjectionGroup::activated(int iMsg)
App::DocumentObject *docObj = getDocument()->getObject(multiViewName.c_str());
auto multiView( static_cast<TechDraw::DrawProjGroup *>(docObj) );
multiView->Source.setValues(shapes);
multiView->XSource.setValues(xShapes);
doCommand(Doc,"App.activeDocument().%s.addProjection('Front')",multiViewName.c_str());
if (faceName.size()) {