TechDraw: Extended Draft View

This commit is contained in:
Yorik van Havre
2016-09-14 12:38:34 -03:00
parent fb9fb9873f
commit d8ebfe58c5
7 changed files with 130 additions and 50 deletions

View File

@@ -52,8 +52,12 @@ DrawViewDraft::DrawViewDraft(void)
static const char *group = "Draft view";
ADD_PROPERTY_TYPE(Source ,(0),group,App::Prop_None,"Draft object for this view");
ADD_PROPERTY_TYPE(LineScale,(1.0),group,App::Prop_None,"Line width adjustment factor for this view");
ADD_PROPERTY_TYPE(LineWidth,(0.35),group,App::Prop_None,"Line width of this view");
ADD_PROPERTY_TYPE(FontSize,(12.0),group,App::Prop_None,"Text size for this view");
ADD_PROPERTY_TYPE(Direction ,(0,0,1.0),group,App::Prop_None,"Projection direction. The direction you are looking from.");
ADD_PROPERTY_TYPE(Color,(0.0f,0.0f,0.0f),group,App::Prop_None,"The default color of text and lines");
ADD_PROPERTY_TYPE(LineStyle,("Solid") ,group,App::Prop_None,"A line style to use for this view. Can be Solid, Dashed, Dashdot, Dot or a SVG pattern like 0.20,0.20");
ADD_PROPERTY_TYPE(LineSpacing,(1.0f),group,App::Prop_None,"The spacing between lines to use for multiline texts");
ScaleType.setValue("Custom");
}
@@ -65,8 +69,12 @@ void DrawViewDraft::onChanged(const App::Property* prop)
{
if (!isRestoring()) {
if (prop == &Source ||
prop == &LineScale ||
prop == &FontSize) {
prop == &LineWidth ||
prop == &FontSize ||
prop == &Direction ||
prop == &Color ||
prop == &LineStyle ||
prop == &LineSpacing) {
try {
App::DocumentObjectExecReturn *ret = recompute();
delete ret;
@@ -87,9 +95,20 @@ App::DocumentObjectExecReturn *DrawViewDraft::execute(void)
std::string svgTail = getSVGTail();
std::string FeatName = getNameInDocument();
std::string SourceName = sourceObj->getNameInDocument();
// Draft.getSVG(obj,scale=1,linewidth=0.35,fontsize=12,fillstyle="shape color",direction=None,linestyle=None,color=None,linespacing=None,techdraw=False)
std::stringstream paramStr;
paramStr << ",scale=" << LineScale.getValue() << ",fontsize=" << FontSize.getValue();
App::Color col = Color.getValue();
paramStr << ",scale=" << Scale.getValue()
<< ",linewidth=" << LineWidth.getValue()
<< ",fontsize=" << FontSize.getValue()
// TODO treat fillstyle here
<< ",direction=FreeCAD.Vector(" << Direction.getValue().x << "," << Direction.getValue().y << "," << Direction.getValue().z << ")"
<< ",linestyle=\"" << LineStyle.getValue() << "\""
<< ",color=\"" << col.asCSSString() << "\""
<< ",linespacing=" << LineSpacing.getValue()
// We must set techdraw to "true" becausea couple of things behave differently than in Drawing
<< ",techdraw=True";
// this is ok for a starting point, but should eventually make dedicated Draft functions that build the svg for all the special cases
// (Arch section, etc)
@@ -124,7 +143,7 @@ namespace App {
/// @cond DOXERR
PROPERTY_SOURCE_TEMPLATE(TechDraw::DrawViewDraftPython, TechDraw::DrawViewDraft)
template<> const char* TechDraw::DrawViewDraftPython::getViewProviderName(void) const {
return "TechDrawGui::ViewProviderSymbol";
return "TechDrawGui::ViewProviderDraft";
}
/// @endcond

View File

@@ -44,8 +44,12 @@ public:
virtual ~DrawViewDraft();
App::PropertyLink Source;
App::PropertyFloat LineScale;
App::PropertyFloat LineWidth;
App::PropertyFloat FontSize;
App::PropertyVector Direction;
App::PropertyColor Color;
App::PropertyString LineStyle;
App::PropertyFloat LineSpacing;
/** @name methods overide Feature */
//@{
@@ -55,7 +59,7 @@ public:
/// returns the type name of the ViewProvider
virtual const char* getViewProviderName(void) const {
return "TechDrawGui::ViewProviderSymbol";
return "TechDrawGui::ViewProviderDraft";
}
protected:

View File

@@ -96,6 +96,7 @@ void TechDrawGuiExport initTechDrawGui()
TechDrawGui::ViewProviderViewClip::init();
TechDrawGui::ViewProviderAnnotation::init();
TechDrawGui::ViewProviderSymbol::init();
TechDrawGui::ViewProviderDraft::init();
TechDrawGui::ViewProviderHatch::init();
TechDrawGui::ViewProviderSpreadsheet::init();

View File

@@ -790,16 +790,15 @@ void CmdTechDrawDraftView::activated(int iMsg)
return;
}
std::vector<App::DocumentObject*> shapes = getSelection().getObjectsOfType(Part::Feature::getClassTypeId());
if (shapes.empty()) {
std::vector<App::DocumentObject*> objects = getSelection().getObjectsOfType(App::DocumentObject::getClassTypeId());
if (objects.empty()) {
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
QObject::tr("Select at least 1 Part object."));
QObject::tr("Select at least one object."));
return;
}
std::string PageName = page->getNameInDocument();
std::string SourceName = shapes.front()->getNameInDocument();
for (std::vector<App::DocumentObject*>::iterator it = shapes.begin(); it != shapes.end(); ++it) {
for (std::vector<App::DocumentObject*>::iterator it = objects.begin(); it != objects.end(); ++it) {
std::string FeatName = getUniqueObjectName("DraftView");
std::string SourceName = (*it)->getNameInDocument();
openCommand("Create DraftView");

View File

@@ -84,3 +84,18 @@ TechDraw::DrawViewSymbol* ViewProviderSymbol::getViewObject() const
{
return dynamic_cast<TechDraw::DrawViewSymbol*>(pcObject);
}
//**************************************************************************
// Draft view
PROPERTY_SOURCE(TechDrawGui::ViewProviderDraft, TechDrawGui::ViewProviderSymbol)
ViewProviderDraft::ViewProviderDraft()
{
sPixmap = "actions/techdraw-draft-view.svg";
}
ViewProviderDraft::~ViewProviderDraft()
{
}

View File

@@ -54,6 +54,17 @@ public:
virtual TechDraw::DrawViewSymbol* getViewObject() const;
};
class TechDrawGuiExport ViewProviderDraft : public ViewProviderSymbol
{
PROPERTY_HEADER(TechDrawGui::ViewProviderDraft);
public:
/// constructor
ViewProviderDraft();
/// destructor
virtual ~ViewProviderDraft();
};
} // namespace TechDrawGui