diff --git a/src/Mod/TechDraw/App/AppTechDraw.cpp b/src/Mod/TechDraw/App/AppTechDraw.cpp index 7bd8d5367e..2b981a5ba6 100644 --- a/src/Mod/TechDraw/App/AppTechDraw.cpp +++ b/src/Mod/TechDraw/App/AppTechDraw.cpp @@ -36,6 +36,7 @@ #include "DrawViewSpreadsheet.h" #include "DrawViewMulti.h" #include "DrawViewImage.h" +#include "DrawViewDetail.h" namespace TechDraw { extern PyObject* initModule(); @@ -74,6 +75,9 @@ PyMODINIT_FUNC initTechDraw() TechDraw::DrawViewDimension ::init(); TechDraw::DrawProjGroup ::init(); TechDraw::DrawProjGroupItem ::init(); + TechDraw::DrawViewDetail ::init(); + + TechDraw::DrawTemplate ::init(); TechDraw::DrawParametricTemplate::init(); TechDraw::DrawSVGTemplate ::init(); diff --git a/src/Mod/TechDraw/App/CMakeLists.txt b/src/Mod/TechDraw/App/CMakeLists.txt index 65b351f245..5d9029f7e4 100644 --- a/src/Mod/TechDraw/App/CMakeLists.txt +++ b/src/Mod/TechDraw/App/CMakeLists.txt @@ -82,7 +82,9 @@ SET(Draw_SRCS DrawViewMulti.cpp DrawViewMulti.h DrawViewImage.cpp - DrawViewImage.h) + DrawViewImage.h + DrawViewDetail.cpp + DrawViewDetail.h) SET(TechDraw_SRCS AppTechDraw.cpp diff --git a/src/Mod/TechDraw/App/DrawUtil.cpp b/src/Mod/TechDraw/App/DrawUtil.cpp index 2422e93668..df44a3da30 100644 --- a/src/Mod/TechDraw/App/DrawUtil.cpp +++ b/src/Mod/TechDraw/App/DrawUtil.cpp @@ -37,6 +37,7 @@ #include +#include #include #include #include @@ -302,7 +303,32 @@ int DrawUtil::vectorCompare(const Base::Vector3d& v1, const Base::Vector3d& v2) return result; } +//!convert fromPoint in coordinate system fromSystem to reference coordinate system +Base::Vector3d DrawUtil::toR3(const gp_Ax2 fromSystem, const Base::Vector3d fromPoint) +{ + gp_Pnt gFromPoint(fromPoint.x,fromPoint.y,fromPoint.z); + gp_Pnt gToPoint; + gp_Trsf T; + gp_Ax3 gRef; + gp_Ax3 gFrom(fromSystem); + T.SetTransformation (gFrom, gRef); + gToPoint = gFromPoint.Transformed(T); + Base::Vector3d toPoint(gToPoint.X(),gToPoint.Y(),gToPoint.Z()); + return toPoint; +} +//! check if direction is parallel to stdZ +bool DrawUtil::checkZParallel(const Base::Vector3d direction) +{ + bool result = false; + Base::Vector3d stdZ(0.0,0.0,1.0); + double dot = fabs(direction.Dot(stdZ)); + double mag = direction.Length() * 1; //stdZ.Length() == 1 + if (DrawUtil::fpCompare(dot,mag)) { + result = true; + } + return result; +} //based on Function provided by Joe Dowsett, 2014 double DrawUtil::sensibleScale(double working_scale) diff --git a/src/Mod/TechDraw/App/DrawUtil.h b/src/Mod/TechDraw/App/DrawUtil.h index 3c7a1636b5..25d4eb9abb 100644 --- a/src/Mod/TechDraw/App/DrawUtil.h +++ b/src/Mod/TechDraw/App/DrawUtil.h @@ -27,6 +27,8 @@ #include #include + +#include #include #include #include @@ -57,6 +59,8 @@ class TechDrawExport DrawUtil { static Base::Vector3d vertex2Vector(const TopoDS_Vertex& v); static std::string formatVector(const Base::Vector3d& v); static int vectorCompare(const Base::Vector3d& v1, const Base::Vector3d& v2); + static Base::Vector3d toR3(const gp_Ax2 fromSystem, const Base::Vector3d fromPoint); + static bool checkZParallel(const Base::Vector3d direction); //debugging routines diff --git a/src/Mod/TechDraw/App/DrawViewDetail.cpp b/src/Mod/TechDraw/App/DrawViewDetail.cpp new file mode 100644 index 0000000000..55e82f0902 --- /dev/null +++ b/src/Mod/TechDraw/App/DrawViewDetail.cpp @@ -0,0 +1,292 @@ +/*************************************************************************** + * Copyright (c) WandererFan (wandererfan@gmail.com) 2016 * + * * + * 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 + +#include +#include +#include +#include +#include +#include +#include +# include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#endif + +#include + +# include +# include + +#include +#include +#include +#include +#include +#include + +#include + +#include "Geometry.h" +#include "GeometryObject.h" +#include "EdgeWalker.h" +#include "DrawProjectSplit.h" +#include "DrawUtil.h" +#include "DrawViewDetail.h" + +using namespace TechDraw; +using namespace std; + + +//=========================================================================== +// DrawViewDetail +//=========================================================================== + +PROPERTY_SOURCE(TechDraw::DrawViewDetail, TechDraw::DrawViewPart) + +DrawViewDetail::DrawViewDetail() : + m_mattingStyle(0) +{ + static const char *dgroup = "Detail"; + + ADD_PROPERTY_TYPE(BaseView ,(0),dgroup,App::Prop_None,"2D View source for this Section"); + ADD_PROPERTY_TYPE(AnchorPoint ,(0,0,0) ,dgroup,App::Prop_None,"Location of detail in BaseView"); + ADD_PROPERTY_TYPE(Radius,(10.0),dgroup, App::Prop_None, "Size of detail area"); + ADD_PROPERTY_TYPE(Reference ,("1"),dgroup,App::Prop_None,"An identifier for this detail"); + + getParameters(); + +} + +DrawViewDetail::~DrawViewDetail() +{ +} + +short DrawViewDetail::mustExecute() const +{ + short result = 0; + if (!isRestoring()) { + result = (AnchorPoint.isTouched() || + Radius.isTouched() || + BaseView.isTouched() || + Reference.isTouched()); + } + if (result) { + return result; + } + return TechDraw::DrawView::mustExecute(); +} + +void DrawViewDetail::onChanged(const App::Property* prop) +{ + if (!isRestoring()) { + //Base::Console().Message("TRACE - DVD::onChanged(%s) - %s\n",prop->getName(),Label.getValue()); + if (prop == &Reference) { + std::string lblText = "Detail " + + std::string(Reference.getValue()); + Label.setValue(lblText); + } + } + DrawView::onChanged(prop); +} + +App::DocumentObjectExecReturn *DrawViewDetail::execute(void) +{ + App::DocumentObject* link = Source.getValue(); + App::DocumentObject* base = BaseView.getValue(); + if (!link || !base) { + Base::Console().Log("INFO - DVD::execute - No Source or Link - creation?\n"); + return DrawView::execute(); + } + + if (!link->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId())) + return new App::DocumentObjectExecReturn("Source object is not a Part object"); + DrawViewPart* dvp = nullptr; + if (!base->getTypeId().isDerivedFrom(TechDraw::DrawViewPart::getClassTypeId())) { + return new App::DocumentObjectExecReturn("BaseView object is not a DrawViewPart object"); + } else { + dvp = static_cast(base); + } + + //Base::Console().Message("TRACE - DVD::execute() - %s/%s\n",getNameInDocument(),Label.getValue()); + + const Part::TopoShape &partTopo = static_cast(link)->Shape.getShape(); + if (partTopo.getShape().IsNull()) + return new App::DocumentObjectExecReturn("Linked shape object is empty"); + + (void) DrawView::execute(); //make sure Scale is up to date + + Base::Vector3d anchor = AnchorPoint.getValue(); //this is a 2D point + anchor = Base::Vector3d(anchor.x,anchor.y, 0.0); + double radiusFudge = 1.1; + double radius = Radius.getValue() * radiusFudge; + Base::Vector3d dirDetail = dvp->Direction.getValue(); + double scale = Scale.getValue(); + gp_Ax2 viewAxis = TechDrawGeometry::getViewAxis(Base::Vector3d(0.0,0.0,0.0), dirDetail, false); + + Base::BoundBox3d bbxSource = partTopo.getBoundBox(); + + BRepBuilderAPI_Copy BuilderCopy(partTopo.getShape()); + TopoDS_Shape myShape = BuilderCopy.Shape(); + + gp_Pnt gpCenter = TechDrawGeometry::findCentroid(myShape, + dirDetail); + Base::Vector3d shapeCenter = Base::Vector3d(gpCenter.X(),gpCenter.Y(),gpCenter.Z()); + double diag = bbxSource.CalcDiagonalLength(); + Base::Vector3d extentFar,extentNear; + extentFar = shapeCenter + dirDetail * diag; + extentNear = shapeCenter + dirDetail * diag * -1.0; + + //turn anchor(x,y,0) in projection plane(P) into displacement in 3D + Base::Vector3d offsetCenter3D = DrawUtil::toR3(viewAxis, anchor); //displacement in R3 + if (DrawUtil::checkZParallel(dirDetail)) { + extentNear = extentNear + offsetCenter3D; + } else { + extentNear = extentNear - offsetCenter3D; + } + + gp_Dir cylDir(dirDetail.x,dirDetail.y,dirDetail.z); + gp_Pnt cylPoint(extentNear.x,extentNear.y,extentNear.z); + gp_Ax2 cylAxis(cylPoint,cylDir); + + BRepPrimAPI_MakeCylinder mkCyl(cylAxis, radius, (extentFar-extentNear).Length()); + TopoDS_Shell sh = mkCyl.Cylinder().Shell(); + BRepBuilderAPI_MakeSolid mkSol(sh); + TopoDS_Solid tool = mkSol.Solid(); + + BRepAlgoAPI_Common mkCommon(myShape,tool); + if (!mkCommon.IsDone()) { + Base::Console().Message("TRACE - DVD::execute - mkCommon not done\n"); + return new App::DocumentObjectExecReturn("DVD::execute - mkCommon not done"); + } + if (mkCommon.Shape().IsNull()) { + Base::Console().Message("TRACE - DVD::execute - mkCommon.Shape is Null\n"); + return new App::DocumentObjectExecReturn("DVD::execute - mkCommon.Shape is Null"); + } + + //Did we get a solid? + TopExp_Explorer xp; + xp.Init(mkCommon.Shape(),TopAbs_SOLID); + if (!(xp.More() == Standard_True)) { + Base::Console().Message("TRACE - DVD::execute - mkCommon.Shape is not a solid!\n"); + } + TopoDS_Shape detail = mkCommon.Shape(); + Bnd_Box testBox; + testBox.SetGap(0.0); + BRepBndLib::Add(detail, testBox); + if (testBox.IsVoid()) { + Base::Console().Message("INFO - DVD::execute - testBox is void\n"); + } + +//for debugging show compound instead of cut +// BRep_Builder builder; +// TopoDS_Compound Comp; +// builder.MakeCompound(Comp); +// builder.Add(Comp, tool); +// builder.Add(Comp, myShape); + + gp_Pnt inputCenter; + try { + inputCenter = TechDrawGeometry::findCentroid(detail, + Direction.getValue()); + TopoDS_Shape mirroredShape = TechDrawGeometry::mirrorShape(detail, + inputCenter, + scale); + geometryObject = buildGeometryObject(mirroredShape,inputCenter); + +#if MOD_TECHDRAW_HANDLE_FACES + if (handleFaces()) { + try { + extractFaces(); + } + catch (Standard_Failure) { + Handle_Standard_Failure e4 = Standard_Failure::Caught(); + Base::Console().Log("LOG - DVD::execute - extractFaces failed for %s - %s **\n",getNameInDocument(),e4->GetMessageString()); + return new App::DocumentObjectExecReturn(e4->GetMessageString()); + } + } + +#endif //#if MOD_TECHDRAW_HANDLE_FACES + } + catch (Standard_Failure) { + Handle_Standard_Failure e1 = Standard_Failure::Caught(); + Base::Console().Log("LOG - DVD::execute - base shape failed for %s - %s **\n",getNameInDocument(),e1->GetMessageString()); + return new App::DocumentObjectExecReturn(e1->GetMessageString()); + } + + + return App::DocumentObject::StdReturn; +} + +void DrawViewDetail::getParameters() +{ +// what parameters are useful? +// handleFaces +// radiusFudge? + + Base::Reference hGrp = App::GetApplication().GetUserParameter() + .GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw"); + m_mattingStyle = hGrp->GetInt("MattingStyle", 0); + +} + +// Python Drawing feature --------------------------------------------------------- + +namespace App { +/// @cond DOXERR +PROPERTY_SOURCE_TEMPLATE(TechDraw::DrawViewDetailPython, TechDraw::DrawViewDetail) +template<> const char* TechDraw::DrawViewDetailPython::getViewProviderName(void) const { + return "TechDrawGui::ViewProviderViewPart"; +} +/// @endcond + +// explicit template instantiation +template class TechDrawExport FeaturePythonT; +} diff --git a/src/Mod/TechDraw/App/DrawViewDetail.h b/src/Mod/TechDraw/App/DrawViewDetail.h new file mode 100644 index 0000000000..7a866e6943 --- /dev/null +++ b/src/Mod/TechDraw/App/DrawViewDetail.h @@ -0,0 +1,85 @@ +/*************************************************************************** + * Copyright (c) WandererFan (wandererfan@gmail.com) 2016 * + * 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 _DrawViewDetail_h_ +#define _DrawViewDetail_h_ + +#include +#include +#include +#include +#include + +#include + +#include + +#include "DrawViewPart.h" + +class gp_Pln; +class gp_Ax2; +class TopoDS_Face; + +namespace TechDrawGeometry +{ +class Face; +} + +namespace TechDraw +{ + + +class TechDrawExport DrawViewDetail : public DrawViewPart +{ + PROPERTY_HEADER(Part::DrawViewDetail); + +public: + /// Constructor + DrawViewDetail(void); + virtual ~DrawViewDetail(); + + App::PropertyLink BaseView; + App::PropertyVector AnchorPoint; + App::PropertyFloat Radius; + App::PropertyString Reference; + + virtual short mustExecute() const; + virtual App::DocumentObjectExecReturn *execute(void); + virtual void onChanged(const App::Property* prop); + virtual const char* getViewProviderName(void) const { + return "TechDrawGui::ViewProviderViewPart"; + } + +public: + int getMattingStyle() const {return m_mattingStyle;} + +protected: + Base::Vector3d toR3(const gp_Ax2 fromSystem, const Base::Vector3d fromPoint); + void getParameters(void); + int m_mattingStyle; + +}; + +typedef App::FeaturePythonT DrawViewDetailPython; + +} //namespace TechDraw + +#endif diff --git a/src/Mod/TechDraw/App/Geometry.cpp b/src/Mod/TechDraw/App/Geometry.cpp index 9c2f6d9e2f..84418050fa 100644 --- a/src/Mod/TechDraw/App/Geometry.cpp +++ b/src/Mod/TechDraw/App/Geometry.cpp @@ -500,7 +500,7 @@ bool BSpline::isLine() bool result = false; BRepAdaptor_Curve c(occEdge); Handle_Geom_BSplineCurve spline = c.BSpline(); - if (spline->Degree() == 1) { + if (spline->NbPoles() == 2) { result = true; } return result; diff --git a/src/Mod/TechDraw/App/GeometryObject.cpp b/src/Mod/TechDraw/App/GeometryObject.cpp index 55503ffe6f..a23138b994 100644 --- a/src/Mod/TechDraw/App/GeometryObject.cpp +++ b/src/Mod/TechDraw/App/GeometryObject.cpp @@ -32,6 +32,7 @@ #include #include #include +#include #include #include #include @@ -280,6 +281,7 @@ void GeometryObject::addGeomFromCompound(TopoDS_Shape edgeCompound, edgeClass ca Base::Console().Log("INFO - GO::addGeomFromCompound - edge: %d is zeroEdge\n",i); continue; } + base = BaseGeom::baseFactory(edge); if (base == nullptr) { Base::Console().Message("Error - GO::addGeomFromCompound - baseFactory failed for edge: %d\n",i); diff --git a/src/Mod/TechDraw/Gui/CMakeLists.txt b/src/Mod/TechDraw/Gui/CMakeLists.txt index 4c941aed68..05798925b5 100644 --- a/src/Mod/TechDraw/Gui/CMakeLists.txt +++ b/src/Mod/TechDraw/Gui/CMakeLists.txt @@ -117,6 +117,8 @@ SET(TechDrawGuiView_SRCS QGISVGTemplate.h QGIVertex.cpp QGIVertex.h + QGIMatting.cpp + QGIMatting.h QGIDrawingTemplate.cpp QGIDrawingTemplate.h QGITemplate.cpp diff --git a/src/Mod/TechDraw/Gui/Command.cpp b/src/Mod/TechDraw/Gui/Command.cpp index 6ec8a21d8c..119164cb2a 100644 --- a/src/Mod/TechDraw/Gui/Command.cpp +++ b/src/Mod/TechDraw/Gui/Command.cpp @@ -64,6 +64,7 @@ #include #include #include +#include #include #include "DrawGuiUtil.h" @@ -375,6 +376,71 @@ bool CmdTechDrawNewViewSection::isActive(void) return (havePage && haveView && !taskInProgress); } +//=========================================================================== +// TechDraw_NewViewDetail +//=========================================================================== + +DEF_STD_CMD_A(CmdTechDrawNewViewDetail); + +CmdTechDrawNewViewDetail::CmdTechDrawNewViewDetail() + : Command("TechDraw_NewViewDetail") +{ + sAppModule = "TechDraw"; + sGroup = QT_TR_NOOP("TechDraw"); + sMenuText = QT_TR_NOOP("Insert detail view in drawing"); + sToolTipText = QT_TR_NOOP("Insert a new Detail View of a Part in the active drawing"); + sWhatsThis = "TechDraw_NewViewDetail"; + sStatusTip = sToolTipText; + sPixmap = "actions/techdraw-viewdetail"; +} + +void CmdTechDrawNewViewDetail::activated(int iMsg) +{ + Q_UNUSED(iMsg); + TechDraw::DrawPage* page = DrawGuiUtil::findPage(this); + if (!page) { + return; + } + + std::vector shapes = getSelection().getObjectsOfType(TechDraw::DrawViewPart::getClassTypeId()); + if (shapes.empty()) { + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), + QObject::tr("Select at least 1 DrawingView object.")); + return; + } + App::DocumentObject* dObj = *(shapes.begin()); + TechDraw::DrawViewPart* dvp = static_cast(dObj); + + std::string PageName = page->getNameInDocument(); + + Gui::WaitCursor wc; + openCommand("Create view"); + + std::string FeatName = getUniqueObjectName("Detail"); + std::string SourceName = dvp->Source.getValue()->getNameInDocument(); + doCommand(Doc,"App.activeDocument().addObject('TechDraw::DrawViewDetail','%s')",FeatName.c_str()); + doCommand(Doc,"App.activeDocument().%s.Source = App.activeDocument().%s",FeatName.c_str(),SourceName.c_str()); + doCommand(Doc,"App.activeDocument().%s.BaseView = App.activeDocument().%s",FeatName.c_str(),(dObj)->getNameInDocument()); + doCommand(Doc,"App.activeDocument().%s.Direction = App.activeDocument().%s.Direction",FeatName.c_str(),(dObj)->getNameInDocument()); + doCommand(Doc,"App.activeDocument().%s.addView(App.activeDocument().%s)",PageName.c_str(),FeatName.c_str()); + + updateActive(); + commitCommand(); +} + +bool CmdTechDrawNewViewDetail::isActive(void) +{ + bool havePage = DrawGuiUtil::needPage(this); + bool haveView = DrawGuiUtil::needView(this); + bool taskInProgress = false; + if (havePage) { + taskInProgress = Gui::Control().activeDialog(); + } + return (havePage && haveView && !taskInProgress); +} + + + //=========================================================================== // TechDraw_ProjGroup //=========================================================================== @@ -1010,6 +1076,7 @@ void CreateTechDrawCommands(void) rcCmdMgr.addCommand(new CmdTechDrawNewPage()); rcCmdMgr.addCommand(new CmdTechDrawNewView()); rcCmdMgr.addCommand(new CmdTechDrawNewViewSection()); + rcCmdMgr.addCommand(new CmdTechDrawNewViewDetail()); rcCmdMgr.addCommand(new CmdTechDrawNewMulti()); rcCmdMgr.addCommand(new CmdTechDrawProjGroup()); rcCmdMgr.addCommand(new CmdTechDrawAnnotation()); diff --git a/src/Mod/TechDraw/Gui/QGIMatting.cpp b/src/Mod/TechDraw/Gui/QGIMatting.cpp new file mode 100644 index 0000000000..67bcfad2f3 --- /dev/null +++ b/src/Mod/TechDraw/Gui/QGIMatting.cpp @@ -0,0 +1,124 @@ +/*************************************************************************** + * Copyright (c) 2016 WandererFan * + * * + * 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 +//#include +//#include +//#include +#include +#include +#endif + +#include +#include +#include +#include + +#include +#include +#include "QGCustomRect.h" +#include "ZVALUE.h" +#include "QGIMatting.h" + +using namespace TechDrawGui; + +QGIMatting::QGIMatting() : + m_height(10.0), + m_width(10.0), + m_holeStyle(0), + m_radius(5.0) + +{ + setCacheMode(QGraphicsItem::NoCache); + setAcceptHoverEvents(false); + setFlag(QGraphicsItem::ItemIsSelectable, false); + setFlag(QGraphicsItem::ItemIsMovable, false); + + m_mat = new QGraphicsPathItem(); //QGIPrimPath?? + addToGroup(m_mat); + m_border = new QGraphicsPathItem(); + addToGroup(m_border); + + m_pen.setColor(Qt::white); + m_brush.setColor(Qt::white); + m_brush.setStyle(Qt::SolidPattern); +// m_pen.setColor(Qt::black); +// m_pen.setStyle(Qt::DashLine); +// m_brush.setStyle(Qt::NoBrush); + m_penB.setColor(Qt::black); + m_brushB.setStyle(Qt::NoBrush); + + m_mat->setPen(m_pen); + m_mat->setBrush(m_brush); + m_border->setPen(m_penB); + m_border->setBrush(m_brushB); + + setZValue(ZVALUE::MATTING); +} + +void QGIMatting::centerAt(QPointF centerPos) +{ + QRectF box = boundingRect(); + double width = box.width(); + double height = box.height(); + double newX = centerPos.x() - width/2.; + double newY = centerPos.y() - height/2.; + setPos(newX,newY); +} + +void QGIMatting::centerAt(double cX, double cY) +{ + QRectF box = boundingRect(); + double width = box.width(); + double height = box.height(); + double newX = cX - width/2.; + double newY = cY - height/2.; + setPos(newX,newY); +} + +void QGIMatting::draw() +{ + QRectF outline(-m_width/2.0,-m_height/2.0,m_width,m_height); + QPainterPath ppOut; + ppOut.addRect(outline); + QPainterPath ppCut; + if (m_holeStyle == 0) { + QRectF roundCutout (-m_radius,-m_radius,2.0 * m_radius,2.0 * m_radius); + ppCut.addEllipse(roundCutout); + } else { + double squareSize = m_radius / 1.4142; //fit within radius + QRectF squareCutout (-squareSize,-squareSize,2.0 * squareSize,2.0 * squareSize); + ppCut.addRect(squareCutout); + } + ppOut.addPath(ppCut); + m_mat->setPath(ppOut); + m_border->setPath(ppCut); +} + +void QGIMatting::paint ( QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget) { + QStyleOptionGraphicsItem myOption(*option); + myOption.state &= ~QStyle::State_Selected; + + QGraphicsItemGroup::paint (painter, &myOption, widget); +} diff --git a/src/Mod/TechDraw/Gui/QGIMatting.h b/src/Mod/TechDraw/Gui/QGIMatting.h new file mode 100644 index 0000000000..567d9391a6 --- /dev/null +++ b/src/Mod/TechDraw/Gui/QGIMatting.h @@ -0,0 +1,82 @@ +/*************************************************************************** + * Copyright (c) 2016 WandererFan * + * * + * 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 DRAWINGGUI_QGIMATTING_H +#define DRAWINGGUI_QGIMATTING_H + +#include +#include +#include +#include +#include +#include + +QT_BEGIN_NAMESPACE +class QPainter; +class QStyleOptionGraphicsItem; +QT_END_NAMESPACE + +namespace TechDrawGui +{ +class QGCustomRect; + +class TechDrawGuiExport QGIMatting : public QGraphicsItemGroup +{ +public: + explicit QGIMatting(void); + ~QGIMatting() {} + + enum {Type = QGraphicsItem::UserType + 205}; + int type() const { return Type;} + + virtual void paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget = 0 ); + virtual void centerAt(QPointF centerPos); + virtual void centerAt(double cX, double cY); + + virtual void setSize(double w, double h) {m_height = h; m_width = w;} + virtual void setHoleStyle(int hs) {m_holeStyle = hs;} + virtual void setRadius(double r) {m_radius = r;} + virtual void draw(void); + +protected: + double m_height; + double m_width; + int m_holeStyle; //round or rect + double m_radius; + + QGraphicsPathItem* m_mat; + QGraphicsPathItem* m_border; + +// QPainterPath m_perimeter; +// QPainterPath m_cutout; + +private: + QPen m_pen; + QBrush m_brush; + QPen m_penB; + QBrush m_brushB; + +}; + +} // namespace MDIViewPageGui + +#endif // DRAWINGGUI_QGIMATTING_H diff --git a/src/Mod/TechDraw/Gui/QGIUserTypes.h b/src/Mod/TechDraw/Gui/QGIUserTypes.h index 3203f9400f..2165a9351d 100644 --- a/src/Mod/TechDraw/Gui/QGIUserTypes.h +++ b/src/Mod/TechDraw/Gui/QGIUserTypes.h @@ -37,6 +37,7 @@ QGICenterLine: 174 QGICaption: 180 QGIViewImage: 200 QGCustomImage: 201 +QGIMatting: 205 */ /* diff --git a/src/Mod/TechDraw/Gui/QGIViewPart.cpp b/src/Mod/TechDraw/Gui/QGIViewPart.cpp index 1f9a390aec..928951b5ac 100644 --- a/src/Mod/TechDraw/Gui/QGIViewPart.cpp +++ b/src/Mod/TechDraw/Gui/QGIViewPart.cpp @@ -51,6 +51,7 @@ #include #include #include +#include #include "ZVALUE.h" #include "QGIFace.h" @@ -61,6 +62,8 @@ #include "QGICenterLine.h" #include "QGCustomBorder.h" #include "QGCustomLabel.h" +#include "QGCustomRect.h" +#include "QGIMatting.h" #include "QGIViewPart.h" using namespace TechDrawGui; @@ -308,6 +311,7 @@ void QGIViewPart::updateView(bool update) void QGIViewPart::draw() { drawViewPart(); drawBorder(); + drawMatting(); } void QGIViewPart::drawViewPart() @@ -486,11 +490,14 @@ void QGIViewPart::removeDecorations() QList children = childItems(); for (auto& c:children) { QGIDecoration* decor = dynamic_cast(c); + QGIMatting* mat = dynamic_cast(c); if (decor) { - removeFromGroup(decor); - scene()->removeItem(decor); - delete decor; + } else if (mat) { + removeFromGroup(mat); + scene()->removeItem(mat); + delete mat; } + } } @@ -601,6 +608,29 @@ void QGIViewPart::drawCenterLines(bool b) } } +void QGIViewPart::drawMatting() +{ + auto viewPart( dynamic_cast(getViewObject()) ); + TechDraw::DrawViewDetail* dvd = nullptr; + if (viewPart->isDerivedFrom(TechDraw::DrawViewDetail::getClassTypeId())) { + dvd = static_cast(viewPart); + } else { + return; + } + + double scale = dvd->Scale.getValue(); + double radius = dvd->Radius.getValue() * scale; + QGIMatting* mat = new QGIMatting(); + addToGroup(mat); + mat->setPos(0.0,0.0); + mat->setRadius(radius); + QRectF displayArea = customChildrenBoundingRect(); + mat->setSize(displayArea.width(),displayArea.height()); + mat->setHoleStyle(dvd->getMattingStyle()); + mat->draw(); + mat->show(); +} + // As called by arc of ellipse case: // pathArc(path, geom->major, geom->minor, geom->angle, geom->largeArc, geom->cw, // geom->endPnt.x, geom->endPnt.y, diff --git a/src/Mod/TechDraw/Gui/QGIViewPart.h b/src/Mod/TechDraw/Gui/QGIViewPart.h index 20afe7b695..d59206ba69 100644 --- a/src/Mod/TechDraw/Gui/QGIViewPart.h +++ b/src/Mod/TechDraw/Gui/QGIViewPart.h @@ -60,6 +60,7 @@ public: virtual QRectF boundingRect() const override; virtual void drawSectionLine(TechDraw::DrawViewSection* s, bool b); virtual void drawCenterLines(bool b); + virtual void drawMatting(void); bool showSection; virtual void draw() override; diff --git a/src/Mod/TechDraw/Gui/Resources/TechDraw.qrc b/src/Mod/TechDraw/Gui/Resources/TechDraw.qrc index 90bd993181..685d8b3e7b 100644 --- a/src/Mod/TechDraw/Gui/Resources/TechDraw.qrc +++ b/src/Mod/TechDraw/Gui/Resources/TechDraw.qrc @@ -48,6 +48,7 @@ icons/actions/techdraw-projgroup.svg icons/actions/techdraw-spreadsheet.svg icons/actions/techdraw-image.svg + icons/actions/techdraw-viewdetail.svg icons/actions/section-up.svg icons/actions/section-down.svg icons/actions/section-left.svg diff --git a/src/Mod/TechDraw/Gui/Resources/icons/actions/techdraw-viewdetail.svg b/src/Mod/TechDraw/Gui/Resources/icons/actions/techdraw-viewdetail.svg new file mode 100644 index 0000000000..9e9632c7ad --- /dev/null +++ b/src/Mod/TechDraw/Gui/Resources/icons/actions/techdraw-viewdetail.svg @@ -0,0 +1,521 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + Jakub Steiner + + + http://jimmac.musichall.cz + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Mod/TechDraw/Gui/Workbench.cpp b/src/Mod/TechDraw/Gui/Workbench.cpp index 66b64fd0c8..26462e84b0 100644 --- a/src/Mod/TechDraw/Gui/Workbench.cpp +++ b/src/Mod/TechDraw/Gui/Workbench.cpp @@ -66,6 +66,7 @@ Gui::MenuItem* Workbench::setupMenuBar() const *draw << "TechDraw_NewMulti"; *draw << "TechDraw_ProjGroup"; *draw << "TechDraw_NewViewSection"; + *draw << "TechDraw_NewViewDetail"; *draw << "TechDraw_Annotation"; *draw << "TechDraw_Symbol"; *draw << "TechDraw_Spreadsheet"; @@ -101,6 +102,7 @@ Gui::ToolBarItem* Workbench::setupToolBars() const *views << "TechDraw_NewMulti"; *views << "TechDraw_ProjGroup"; *views << "TechDraw_NewViewSection"; + *views << "TechDraw_NewViewDetail"; *views << "TechDraw_Annotation"; *views << "TechDraw_DraftView"; *views << "TechDraw_ArchView"; @@ -150,6 +152,7 @@ Gui::ToolBarItem* Workbench::setupCommandBars() const *views << "TechDraw_NewMulti"; *views << "TechDraw_ProjGroup"; *views << "TechDraw_NewViewSection"; + *views << "TechDraw_NewViewDetail"; *views << "TechDraw_Annotation"; *views << "TechDraw_DraftView"; *views << "TechDraw_Spreadsheet"; diff --git a/src/Mod/TechDraw/Gui/ZVALUE.h b/src/Mod/TechDraw/Gui/ZVALUE.h index 7a474e66e9..559e6ad6cf 100644 --- a/src/Mod/TechDraw/Gui/ZVALUE.h +++ b/src/Mod/TechDraw/Gui/ZVALUE.h @@ -14,5 +14,6 @@ namespace ZVALUE { const int SECTIONHATCH = 66; const int DIMENSION = 70; const int SECTIONLINE = 80; //TODO: change to "DECORATION"? section lines, symmetry lines, etc? + const int MATTING = 100; } #endif