Skip to content

Commit

Permalink
[TD]support App::Link in View Source
Browse files Browse the repository at this point in the history
  • Loading branch information
WandererFan committed Mar 13, 2020
1 parent 8705a6f commit 37b578b
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 15 deletions.
2 changes: 2 additions & 0 deletions src/Mod/TechDraw/App/DrawProjGroup.cpp
Expand Up @@ -72,6 +72,8 @@ 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(Anchor, (0), group, App::Prop_None, "The root view to align projections with");
Anchor.setScope(App::LinkScope::Global);

Expand Down
3 changes: 3 additions & 0 deletions src/Mod/TechDraw/App/DrawViewPart.cpp
Expand Up @@ -142,6 +142,8 @@ DrawViewPart::DrawViewPart(void) :
//properties that affect Geometry
ADD_PROPERTY_TYPE(Source ,(0),group,App::Prop_None,"3D Shape to view");
Source.setScope(App::LinkScope::Global);
Source.setAllowExternal(true);

ADD_PROPERTY_TYPE(Direction ,(0.0,-1.0,0.0),
group,App::Prop_None,"Projection Plane normal. The direction you are looking from.");
ADD_PROPERTY_TYPE(XDirection ,(0.0,0.0,0.0),
Expand Down Expand Up @@ -244,6 +246,7 @@ App::DocumentObjectExecReturn *DrawViewPart::execute(void)
}
return App::DocumentObject::StdReturn;
}
std::vector<App::DocumentObject*> sources = Source.getValues();

TopoDS_Shape shape = getSourceShape();
if (shape.IsNull()) {
Expand Down
112 changes: 99 additions & 13 deletions src/Mod/TechDraw/App/ShapeExtractor.cpp
Expand Up @@ -39,12 +39,14 @@
#include <App/Document.h>
#include <App/GroupExtension.h>
#include <App/Part.h>
#include <App/Link.h>

#include <Base/BoundBox.h>
#include <Base/Console.h>
#include <Base/Exception.h>
#include <Base/FileInfo.h>
#include <Base/Parameter.h>
#include <Base/Placement.h>

#include <Mod/Part/App/PartFeature.h>
#include <Mod/Part/App/PrimitiveFeature.h>
Expand All @@ -67,7 +69,6 @@ std::vector<TopoDS_Shape> ShapeExtractor::getShapes2d(const std::vector<App::Doc
}
for (auto& l:links) {
const App::GroupExtension* gex = dynamic_cast<const App::GroupExtension*>(l);
// App::Property* gProp = l->getPropertyByName("Group");
if (gex != nullptr) {
std::vector<App::DocumentObject*> objs = gex->Group.getValues();
for (auto& d: objs) {
Expand All @@ -92,24 +93,34 @@ std::vector<TopoDS_Shape> ShapeExtractor::getShapes2d(const std::vector<App::Doc

TopoDS_Shape ShapeExtractor::getShapes(const std::vector<App::DocumentObject*> links)
{
// Base::Console().Message("SE::getShapes() - links in: %d\n", links.size());
TopoDS_Shape result;
std::vector<TopoDS_Shape> sourceShapes;

for (auto& l:links) {
auto shape = Part::Feature::getShape(l);
if(!shape.IsNull()) {
// BRepTools::Write(shape, "DVPgetShape.brep"); //debug
if (shape.ShapeType() > TopAbs_COMPSOLID) { //simple shape
sourceShapes.push_back(shape);
} else { //complex shape
std::vector<TopoDS_Shape> drawable = extractDrawableShapes(shape);
if (!drawable.empty()) {
sourceShapes.insert(sourceShapes.end(),drawable.begin(),drawable.end());
}
if (l->getTypeId().isDerivedFrom(App::Link::getClassTypeId())) {
App::Link* xLink = dynamic_cast<App::Link*>(l);
std::vector<TopoDS_Shape> xShapes = getXShapes(xLink);
if (!xShapes.empty()) {
sourceShapes.insert(sourceShapes.end(), xShapes.begin(), xShapes.end());
continue;
}
} else {
std::vector<TopoDS_Shape> shapeList = getShapesFromObject(l);
sourceShapes.insert(sourceShapes.end(),shapeList.begin(),shapeList.end());
auto shape = Part::Feature::getShape(l);
if(!shape.IsNull()) {
// BRepTools::Write(shape, "DVPgetShape.brep"); //debug
if (shape.ShapeType() > TopAbs_COMPSOLID) { //simple shape
sourceShapes.push_back(shape);
} else { //complex shape
std::vector<TopoDS_Shape> drawable = extractDrawableShapes(shape);
if (!drawable.empty()) {
sourceShapes.insert(sourceShapes.end(),drawable.begin(),drawable.end());
}
}
} else {
std::vector<TopoDS_Shape> shapeList = getShapesFromObject(l);
sourceShapes.insert(sourceShapes.end(),shapeList.begin(),shapeList.end());
}
}
}

Expand All @@ -136,6 +147,81 @@ TopoDS_Shape ShapeExtractor::getShapes(const std::vector<App::DocumentObject*> l
return result;
}

std::vector<TopoDS_Shape> ShapeExtractor::getXShapes(const App::Link* xLink)
{
// Base::Console().Message("SE::getXShapes(%X) - %s\n", xLink, xLink->getNameInDocument());
std::vector<TopoDS_Shape> xSourceShapes;
if (xLink == nullptr) {
return xSourceShapes;
}

std::vector<App::DocumentObject*> children = xLink->getLinkedChildren();
Base::Placement linkPlm;
if (xLink->hasPlacement()) {
linkPlm = xLink->getLinkPlacementProperty()->getValue();
}

if (!children.empty()) {
for (auto& l:children) {
//What to do with LinkGroup???
// if (l->getTypeId().isDerivedFrom(App::LinkGroup::getClassTypeId())) {
// Base::Console().Message("SE::getXShapes - found a LinkGroup\n");
// }
Base::Placement childPlm;
if (l->getTypeId().isDerivedFrom(App::LinkElement::getClassTypeId())) {
App::LinkElement* cLinkElem = dynamic_cast<App::LinkElement*>(l);
if (cLinkElem->hasPlacement()) {
childPlm = cLinkElem->getLinkPlacementProperty()->getValue();
}
}
auto shape = Part::Feature::getShape(l);
if(!shape.IsNull()) {
Base::Placement netPlm = linkPlm;
netPlm *= childPlm;
if (xLink->hasPlacement()) {
Part::TopoShape ts(shape);
ts.setPlacement(netPlm);
shape = ts.getShape();
}
if (shape.ShapeType() > TopAbs_COMPSOLID) { //simple shape
xSourceShapes.push_back(shape);
} else { //complex shape
std::vector<TopoDS_Shape> drawable = extractDrawableShapes(shape);
if (!drawable.empty()) {
xSourceShapes.insert(xSourceShapes.end(),drawable.begin(),drawable.end());
}
}
} else {
Base::Console().Message("SE::getXShapes - no shape from getXShape\n");
}
}
} else {
int depth = 1; //0 is default value, related to recursion of Links???
App::DocumentObject* link = xLink->getLink(depth);
if (link != nullptr) {
auto shape = Part::Feature::getShape(link);
if(!shape.IsNull()) {
if (xLink->hasPlacement()) {
Part::TopoShape ts(shape);
ts.setPlacement(linkPlm);
shape = ts.getShape();
}

if (shape.ShapeType() > TopAbs_COMPSOLID) { //simple shape
xSourceShapes.push_back(shape);
} else { //complex shape
std::vector<TopoDS_Shape> drawable = extractDrawableShapes(shape);
if (!drawable.empty()) {
xSourceShapes.insert(xSourceShapes.end(),drawable.begin(),drawable.end());
}
}
}
}
}
return xSourceShapes;
}


std::vector<TopoDS_Shape> ShapeExtractor::getShapesFromObject(const App::DocumentObject* docObj)
{
// Base::Console().Message("SE::getShapesFromObject(%s)\n", docObj->getNameInDocument());
Expand Down
2 changes: 2 additions & 0 deletions src/Mod/TechDraw/App/ShapeExtractor.h
Expand Up @@ -32,6 +32,7 @@
#include <App/FeaturePython.h>
#include <App/GroupExtension.h>
#include <App/Part.h>
#include <App/Link.h>
#include <App/PropertyLinks.h>
#include <App/PropertyStandard.h>

Expand All @@ -46,6 +47,7 @@ class TechDrawExport ShapeExtractor
public:
static TopoDS_Shape getShapes(const std::vector<App::DocumentObject*> links);
static std::vector<TopoDS_Shape> getShapes2d(const std::vector<App::DocumentObject*> links);
static std::vector<TopoDS_Shape> getXShapes(const App::Link* xLink);
static std::vector<TopoDS_Shape> getShapesFromObject(const App::DocumentObject* docObj);
static TopoDS_Shape getShapesFused(const std::vector<App::DocumentObject*> links);
static std::vector<TopoDS_Shape> extractDrawableShapes(const TopoDS_Shape shapeIn);
Expand Down
4 changes: 2 additions & 2 deletions src/Mod/TechDraw/Gui/Command.cpp
Expand Up @@ -316,7 +316,7 @@ void CmdTechDrawView::activated(int iMsg)
if (obj->isDerivedFrom(TechDraw::DrawPage::getClassTypeId()) ) {
continue;
}
if (obj != nullptr) { //can this happen?
if (obj != nullptr) {
shapes.push_back(obj);
}
if(partObj != nullptr) {
Expand All @@ -333,7 +333,7 @@ void CmdTechDrawView::activated(int iMsg)

if ((shapes.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;
}

Expand Down

0 comments on commit 37b578b

Please sign in to comment.