Skip to content

Commit

Permalink
TechDraw: Arch View
Browse files Browse the repository at this point in the history
  • Loading branch information
yorikvanhavre committed Oct 28, 2016
1 parent 5f12a79 commit 54a8e85
Show file tree
Hide file tree
Showing 12 changed files with 1,035 additions and 177 deletions.
347 changes: 170 additions & 177 deletions src/Mod/Arch/ArchSectionPlane.py

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions src/Mod/TechDraw/App/AppTechDraw.cpp
Expand Up @@ -32,6 +32,7 @@
#include "DrawViewClip.h"
#include "DrawHatch.h"
#include "DrawViewDraft.h"
#include "DrawViewArch.h"
#include "DrawViewSpreadsheet.h"

namespace TechDraw {
Expand Down Expand Up @@ -77,6 +78,7 @@ PyMODINIT_FUNC initTechDraw()
TechDraw::DrawViewClip ::init();
TechDraw::DrawHatch ::init();
TechDraw::DrawViewDraft ::init();
TechDraw::DrawViewArch ::init();

// Python Types
TechDraw::DrawViewPython ::init();
Expand Down
2 changes: 2 additions & 0 deletions src/Mod/TechDraw/App/CMakeLists.txt
Expand Up @@ -77,6 +77,8 @@ SET(Draw_SRCS
DrawHatch.h
DrawViewDraft.cpp
DrawViewDraft.h
DrawViewArch.cpp
DrawViewArch.h
)

SET(TechDraw_SRCS
Expand Down
132 changes: 132 additions & 0 deletions src/Mod/TechDraw/App/DrawViewArch.cpp
@@ -0,0 +1,132 @@
/***************************************************************************
* Copyright (c) York van Havre 2016 yorik@uncreated.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 <sstream>
#endif

#include <iomanip>

#include <Base/Console.h>
#include <Base/Exception.h>
#include <Base/FileInfo.h>
#include <Base/Interpreter.h>

#include "DrawViewArch.h"

using namespace TechDraw;
using namespace std;


//===========================================================================
// DrawViewArch
//===========================================================================

PROPERTY_SOURCE(TechDraw::DrawViewArch, TechDraw::DrawViewSymbol)

const char* DrawViewArch::RenderModeEnums[]= {"Wireframe",
"Solid",
NULL};

DrawViewArch::DrawViewArch(void)
{
static const char *group = "Arch view";

ADD_PROPERTY_TYPE(Source ,(0),group,App::Prop_None,"Section Plane object for this view");
ADD_PROPERTY_TYPE(AllOn ,(false),group,App::Prop_None,"If hidden objects must be shown or not");
RenderMode.setEnums(RenderModeEnums);
ADD_PROPERTY_TYPE(RenderMode, ((long)0),group,App::Prop_None,"The render mode to use");
ADD_PROPERTY_TYPE(ShowHidden ,(false),group,App::Prop_None,"If the hidden geometry behind the section plane is shown or not");
ADD_PROPERTY_TYPE(ShowFill ,(false),group,App::Prop_None,"If cut areas must be filled with a hatch pattern or not");
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");
ScaleType.setValue("Custom");
}

DrawViewArch::~DrawViewArch()
{
}

void DrawViewArch::onChanged(const App::Property* prop)
{
if (!isRestoring()) {
if (prop == &Source ||
prop == &AllOn ||
prop == &RenderMode ||
prop == &ShowHidden ||
prop == &ShowFill ||
prop == &LineWidth ||
prop == &FontSize) {
try {
App::DocumentObjectExecReturn *ret = recompute();
delete ret;
}
catch (...) {
}
}
}
TechDraw::DrawViewSymbol::onChanged(prop);
}

App::DocumentObjectExecReturn *DrawViewArch::execute(void)
{
App::DocumentObject* sourceObj = Source.getValue();
if (sourceObj) {
std::string svgFrag;
std::string svgHead = getSVGHead();
std::string svgTail = getSVGTail();
std::string FeatName = getNameInDocument();
std::string SourceName = sourceObj->getNameInDocument();
// ArchSectionPlane.getSVG(section,allOn=False,renderMode="Wireframe",showHidden=False,showFill=False,scale=1,linewidth=1,fontsize=1):

std::stringstream paramStr;
paramStr << ",allOn=" << (AllOn.getValue() ? "True" : "False")
<< ",renderMode=\"" << RenderMode.getValue() << "\""
<< ",showHidden=" << (ShowHidden.getValue() ? "True" : "False")
<< ",showFill=" << (ShowFill.getValue() ? "True" : "False")
<< ",linewidth=" << LineWidth.getValue()
<< ",fontsize=" << FontSize.getValue();
Base::Interpreter().runString("import ArchSectionPlane");
Base::Interpreter().runStringArg("svgBody = ArchSectionPlane.getSVG(App.activeDocument().%s %s)",
SourceName.c_str(),paramStr.str().c_str());
Base::Interpreter().runStringArg("App.activeDocument().%s.Symbol = '%s' + svgBody + '%s'",
FeatName.c_str(),svgHead.c_str(),svgTail.c_str());
}
return DrawView::execute();
}

std::string DrawViewArch::getSVGHead(void)
{
std::string head = std::string("<svg\\n") +
std::string(" xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\"\\n") +
std::string(" xmlns:freecad=\"http://www.freecadweb.org/wiki/index.php?title=Svg_Namespace\">\\n");
return head;
}

std::string DrawViewArch::getSVGTail(void)
{
std::string tail = "\\n</svg>";
return tail;
}
77 changes: 77 additions & 0 deletions src/Mod/TechDraw/App/DrawViewArch.h
@@ -0,0 +1,77 @@
/***************************************************************************
* Copyright (c) York van Havre 2016 yorik@uncreated.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 _DrawViewArch_h_
#define _DrawViewArch_h_

#include <App/DocumentObject.h>
#include <Base/BoundBox.h>
#include <App/FeaturePython.h>
#include <App/PropertyLinks.h>

#include "DrawViewSymbol.h"

namespace TechDraw
{

class TechDrawExport DrawViewArch : public TechDraw::DrawViewSymbol
{
PROPERTY_HEADER(TechDraw::DrawViewArch);

public:
/// Constructor
DrawViewArch(void);
virtual ~DrawViewArch();

App::PropertyLink Source;
App::PropertyBool AllOn;
App::PropertyEnumeration RenderMode; // "Wireframe","Solid"
App::PropertyBool ShowHidden;
App::PropertyBool ShowFill;
App::PropertyFloat LineWidth;
App::PropertyFloat FontSize;

/** @name methods overide Feature */
//@{
/// recalculate the Feature
virtual App::DocumentObjectExecReturn *execute(void);
//@}

/// returns the type name of the ViewProvider
virtual const char* getViewProviderName(void) const {
return "TechDrawGui::ViewProviderArch";
}

protected:
virtual void onChanged(const App::Property* prop);
Base::BoundBox3d bbox;
std::string getSVGHead(void);
std::string getSVGTail(void);

private:
static const char* RenderModeEnums[];
};

} //namespace TechDraw


#endif
1 change: 1 addition & 0 deletions src/Mod/TechDraw/Gui/AppTechDrawGui.cpp
Expand Up @@ -97,6 +97,7 @@ void TechDrawGuiExport initTechDrawGui()
TechDrawGui::ViewProviderAnnotation::init();
TechDrawGui::ViewProviderSymbol::init();
TechDrawGui::ViewProviderDraft::init();
TechDrawGui::ViewProviderArch::init();
TechDrawGui::ViewProviderHatch::init();
TechDrawGui::ViewProviderSpreadsheet::init();

Expand Down
58 changes: 58 additions & 0 deletions src/Mod/TechDraw/Gui/Command.cpp
Expand Up @@ -789,6 +789,63 @@ bool CmdTechDrawDraftView::isActive(void)
return DrawGuiUtil::needPage(this);
}

//===========================================================================
// TechDraw_ArchView
//===========================================================================

DEF_STD_CMD_A(CmdTechDrawArchView);

CmdTechDrawArchView::CmdTechDrawArchView()
: Command("TechDraw_ArchView")
{
// setting the Gui eye-candy
sGroup = QT_TR_NOOP("TechDraw");
sMenuText = QT_TR_NOOP("Insert an ArchView");
sToolTipText = QT_TR_NOOP("Inserts a view of an Arch Section Plane into the active drawing");
sWhatsThis = "TechDraw_ArchView";
sStatusTip = QT_TR_NOOP("Inserts a view of an Arch Section Plane into the active drawing");
sPixmap = "actions/techdraw-arch-view";
}

void CmdTechDrawArchView::activated(int iMsg)
{
Q_UNUSED(iMsg);
TechDraw::DrawPage* page = DrawGuiUtil::findPage(this);
if (!page) {
return;
}

std::vector<App::DocumentObject*> objects = getSelection().getObjectsOfType(App::DocumentObject::getClassTypeId());
if (objects.size() != 1) {
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
QObject::tr("Select exactly one Arch Section Plane object."));
return;
}
App::Property* prop1 = objects[0]->getPropertyByName("Objects");
App::Property* prop2 = objects[0]->getPropertyByName("OnlySolids");
if ( (!prop1) || (!prop2) ) {
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
QObject::tr("The selected object is not an Arch Section Plane."));
return;
}

std::string PageName = page->getNameInDocument();

std::string FeatName = getUniqueObjectName("ArchView");
std::string SourceName = objects[0]->getNameInDocument();
openCommand("Create ArchView");
doCommand(Doc,"App.activeDocument().addObject('TechDraw::DrawViewArch','%s')",FeatName.c_str());
doCommand(Doc,"App.activeDocument().%s.Source = App.activeDocument().%s",FeatName.c_str(),SourceName.c_str());
doCommand(Doc,"App.activeDocument().%s.addView(App.activeDocument().%s)",PageName.c_str(),FeatName.c_str());
updateActive();
commitCommand();
}

bool CmdTechDrawArchView::isActive(void)
{
return DrawGuiUtil::needPage(this);
}

//===========================================================================
// TechDraw_Spreadheet
//===========================================================================
Expand Down Expand Up @@ -910,5 +967,6 @@ void CreateTechDrawCommands(void)
rcCmdMgr.addCommand(new CmdTechDrawSymbol());
rcCmdMgr.addCommand(new CmdTechDrawExportPage());
rcCmdMgr.addCommand(new CmdTechDrawDraftView());
rcCmdMgr.addCommand(new CmdTechDrawArchView());
rcCmdMgr.addCommand(new CmdTechDrawSpreadsheet());
}
1 change: 1 addition & 0 deletions src/Mod/TechDraw/Gui/Resources/TechDraw.qrc
Expand Up @@ -38,6 +38,7 @@
<file>icons/actions/techdraw-clipminus.svg</file>
<file>icons/actions/techdraw-symbol.svg</file>
<file>icons/actions/techdraw-draft-view.svg</file>
<file>icons/actions/techdraw-arch-view.svg</file>
<file>icons/actions/techdraw-saveSVG.svg</file>
<file>icons/actions/techdraw-viewsection.svg</file>
<file>icons/actions/techdraw-hatch.svg</file>
Expand Down

0 comments on commit 54a8e85

Please sign in to comment.