/*************************************************************************** * Copyright (c) 2019 WandererFan * * Copyright (c) 2022 Benjamin Bræstrup Sayoc * * * * 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 #endif #include #include #include #include #include "Cosmetic.h" #include "DrawUtil.h" #include "DrawViewPart.h" #include "GeometryObject.h" #include "LineGroup.h" #include "Preferences.h" using namespace TechDraw; using namespace std; #define GEOMETRYEDGE 0 #define COSMETICEDGE 1 #define CENTERLINE 2 LineFormat::LineFormat() { m_style = getDefEdgeStyle(); m_weight = getDefEdgeWidth(); m_color= getDefEdgeColor(); m_visible = true; } LineFormat::LineFormat(int style, double weight, App::Color color, bool visible) : m_style(style), m_weight(weight), m_color(color), m_visible(visible) { } void LineFormat::dump(const char* title) { Base::Console().Message("LF::dump - %s \n", title); Base::Console().Message("LF::dump - %s \n", toString().c_str()); } std::string LineFormat::toString() const { std::stringstream ss; ss << m_style << ", " << m_weight << ", " << m_color.asHexString() << ", " << m_visible; return ss.str(); } //static preference getters. double LineFormat::getDefEdgeWidth() { return TechDraw::LineGroup::getDefaultWidth("Graphic"); } App::Color LineFormat::getDefEdgeColor() { return Preferences::normalColor(); } int LineFormat::getDefEdgeStyle() { Base::Reference hGrp = App::GetApplication().GetUserParameter() .GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw/Decorations"); int style = hGrp->GetInt("CosmoCLStyle", 2); //dashed return style; } //****************************************** TYPESYSTEM_SOURCE(TechDraw::CosmeticEdge, Base::Persistence) //note this ctor has no occEdge or first/last point for geometry! CosmeticEdge::CosmeticEdge() { // Base::Console().Message("CE::CE()\n"); permaRadius = 0.0; m_geometry = std::make_shared (); initialize(); } CosmeticEdge::CosmeticEdge(CosmeticEdge* ce) { // Base::Console().Message("CE::CE(ce)\n"); TechDraw::BaseGeomPtr newGeom = ce->m_geometry->copy(); //these endpoints are already YInverted permaStart = ce->permaStart; permaEnd = ce->permaEnd; permaRadius = ce->permaRadius; m_geometry = newGeom; m_format = ce->m_format; initialize(); } CosmeticEdge::CosmeticEdge(Base::Vector3d pt1, Base::Vector3d pt2) : // 🠓 returns TopoDS_Edge CosmeticEdge::CosmeticEdge(TopoDS_EdgeFromVectors(pt1, pt2)) { } // 🠓 returns TechDraw::BaseGeomPtr CosmeticEdge::CosmeticEdge(TopoDS_Edge e) : CosmeticEdge(TechDraw::BaseGeom::baseFactory(e)) { } CosmeticEdge::CosmeticEdge(TechDraw::BaseGeomPtr g) { // Base::Console().Message("CE::CE(bg)\n"); m_geometry = g; //we assume input edge is already in Yinverted coordinates permaStart = m_geometry->getStartPoint(); permaEnd = m_geometry->getEndPoint(); if ((g->getGeomType() == TechDraw::GeomType::CIRCLE) || (g->getGeomType() == TechDraw::GeomType::ARCOFCIRCLE)) { TechDraw::CirclePtr circ = std::static_pointer_cast(g); permaStart = circ->center; permaEnd = circ->center; permaRadius = circ->radius; } initialize(); } CosmeticEdge::~CosmeticEdge() { //shared pointer will delete m_geometry when ref count goes to zero. } void CosmeticEdge::initialize() { m_geometry->setClassOfEdge(ecHARD); m_geometry->setHlrVisible( true); m_geometry->setCosmetic(true); m_geometry->source(COSMETICEDGE); createNewTag(); m_geometry->setCosmeticTag(getTagAsString()); } TopoDS_Edge CosmeticEdge::TopoDS_EdgeFromVectors(Base::Vector3d pt1, Base::Vector3d pt2) { // Base::Console().Message("CE::CE(p1, p2)\n"); Base::Vector3d p1 = DrawUtil::invertY(pt1); Base::Vector3d p2 = DrawUtil::invertY(pt2); gp_Pnt gp1(p1.x, p1.y, p1.z); gp_Pnt gp2(p2.x, p2.y, p2.z); TopoDS_Edge e = BRepBuilderAPI_MakeEdge(gp1, gp2); return e; } TechDraw::BaseGeomPtr CosmeticEdge::scaledGeometry(double scale) { TopoDS_Edge e = m_geometry->getOCCEdge(); TopoDS_Shape s = TechDraw::scaleShape(e, scale); TopoDS_Edge newEdge = TopoDS::Edge(s); TechDraw::BaseGeomPtr newGeom = TechDraw::BaseGeom::baseFactory(newEdge); newGeom->setClassOfEdge(ecHARD); newGeom->setHlrVisible( true); newGeom->setCosmetic(true); newGeom->source(COSMETICEDGE); newGeom->setCosmeticTag(getTagAsString()); return newGeom; } std::string CosmeticEdge::toString() const { std::stringstream ss; ss << getTagAsString() << ", $$$, "; if (m_geometry) { ss << m_geometry->getGeomType() << ", $$$, " << m_geometry->toString() << ", $$$, " << m_format.toString(); } return ss.str(); } void CosmeticEdge::dump(const char* title) { Base::Console().Message("CE::dump - %s \n", title); Base::Console().Message("CE::dump - %s \n", toString().c_str()); } // Persistence implementers unsigned int CosmeticEdge::getMemSize () const { return 1; } void CosmeticEdge::Save(Base::Writer &writer) const { writer.Stream() << writer.ind() << "