| 76 | |
| 77 | |
| 78 | App::DocumentObjectExecReturn *DrawViewDraft::execute() |
| 79 | { |
| 80 | // Base::Console().message("DVDr::execute() \n"); |
| 81 | if (!keepUpdated()) { |
| 82 | return App::DocumentObject::StdReturn; |
| 83 | } |
| 84 | |
| 85 | App::DocumentObject* sourceObj = Source.getValue(); |
| 86 | if (sourceObj) { |
| 87 | std::string svgFrag; |
| 88 | std::string svgHead = getSVGHead(); |
| 89 | std::string svgTail = getSVGTail(); |
| 90 | std::string FeatName = getNameInDocument(); |
| 91 | std::string SourceName = sourceObj->getNameInDocument(); |
| 92 | // Draft.get_svg(obj, scale=1, linewidth=0.35, fontsize=12, fillstyle="shape color", direction=None, linestyle=None, color=None, linespacing=None, techdraw=False) |
| 93 | |
| 94 | std::stringstream paramStr; |
| 95 | Base::Color col = Color.getValue(); |
| 96 | paramStr << ", scale=" << getScale() |
| 97 | << ", linewidth=" << LineWidth.getValue() |
| 98 | << ", fontsize=" << FontSize.getValue() |
| 99 | // TODO treat fillstyle here |
| 100 | << ", direction=FreeCAD.Vector(" << Direction.getValue().x << ", " << Direction.getValue().y << ", " << Direction.getValue().z << ")" |
| 101 | << ", linestyle=\"" << LineStyle.getValue() << "\"" |
| 102 | << ", color=\"" << col.asHexString() << "\"" |
| 103 | << ", linespacing=" << LineSpacing.getValue() |
| 104 | // We must set techdraw to "true" becausea couple of things behave differently than in Drawing |
| 105 | << ", techdraw=True" |
| 106 | << ", override=" << (OverrideStyle.getValue() ? "True" : "False"); |
| 107 | |
| 108 | // this is ok for a starting point, but should eventually make dedicated Draft functions that build the svg for all the special cases |
| 109 | // (Arch section, etc) |
| 110 | // like Draft.makeDrawingView, but we don't need to create the actual document objects in Draft, just the svg. |
| 111 | Base::Interpreter().runString("import Draft"); |
| 112 | Base::Interpreter().runStringArg("svgBody = Draft.get_svg(App.activeDocument().%s %s)", |
| 113 | SourceName.c_str(), paramStr.str().c_str()); |
| 114 | // Base::Interpreter().runString("print svgBody"); |
| 115 | Base::Interpreter().runStringArg("App.activeDocument().%s.Symbol = '%s' + svgBody + '%s'", |
| 116 | FeatName.c_str(), svgHead.c_str(), svgTail.c_str()); |
| 117 | } |
| 118 | |
| 119 | overrideKeepUpdated(false); |
| 120 | return DrawView::execute(); |
| 121 | } |
| 122 | |
| 123 | std::string DrawViewDraft::getSVGHead() |
| 124 | { |
nothing calls this directly
no test coverage detected