Initial version addCosmeticVertex

This commit is contained in:
wandererfan
2019-05-15 07:37:36 -04:00
parent dd6673a6e1
commit 3f7570ad80
32 changed files with 3157 additions and 379 deletions

View File

@@ -123,6 +123,8 @@ SET(Geometry_SRCS
Geometry.h
GeometryObject.cpp
GeometryObject.h
Cosmetic.cpp
Cosmetic.h
)
SET(Python_SRCS

View File

@@ -0,0 +1,143 @@
/***************************************************************************
* Copyright (c) 2019 WandererFan <wandererfan@gmail.com> *
* *
* 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_
#endif // #ifndef _PreComp_
#include <Base/Console.h>
#include <Base/Exception.h>
#include <Base/Parameter.h>
#include <Base/Vector3D.h>
#include <App/Application.h>
#include <App/Material.h>
#include "DrawUtil.h"
#include "Cosmetic.h"
using namespace TechDraw;
CosmeticVertex::CosmeticVertex()
{
pageLocation = Base::Vector3d(0.0, 0.0, 0.0);
modelLocation = Base::Vector3d(0.0, 0.0, 0.0);
Base::Reference<ParameterGrp> hGrp = App::GetApplication().GetUserParameter().GetGroup("BaseApp")->
GetGroup("Preferences")->GetGroup("Mod/TechDraw/Decorations");
App::Color fcColor;
fcColor.setPackedValue(hGrp->GetUnsigned("VertexColor", 0x00000000));
linkGeom = -1;
color = fcColor;
size = 3.0;
style = 1;
visible = true;
}
CosmeticVertex::CosmeticVertex(Base::Vector3d loc)
{
pageLocation = loc;
modelLocation = loc;
Base::Reference<ParameterGrp> hGrp = App::GetApplication().GetUserParameter().GetGroup("BaseApp")->
GetGroup("Preferences")->GetGroup("Mod/TechDraw/Decorations");
App::Color fcColor;
fcColor.setPackedValue(hGrp->GetUnsigned("VertexColor", 0xff000000));
linkGeom = -1;
color = fcColor;
//TODO: size = hGrp->getFloat("VertexSize",30.0);
size = 30.0;
style = 1; //TODO: implement styled vertexes
visible = true;
}
std::string CosmeticVertex::toCSV(void) const
{
std::stringstream ss;
ss << pageLocation.x << "," <<
pageLocation.y << "," <<
pageLocation.z << "," <<
modelLocation.x << "," <<
modelLocation.y << "," <<
modelLocation.z << "," <<
linkGeom << "," <<
color.asHexString() << "," <<
size << "," <<
style << "," <<
visible <<
std::endl;
return ss.str();
}
bool CosmeticVertex::fromCSV(std::string& lineSpec)
{
unsigned int maxCells = 11;
if (lineSpec.length() == 0) {
Base::Console().Message( "CosmeticVertex::fromCSV - lineSpec empty\n");
return false;
}
std::vector<std::string> values = split(lineSpec);
Base::Console().Message("CV::fromCSV - values: %d\n",values.size());
if (values.size() < maxCells) {
Base::Console().Message( "CosmeticVertex::fromCSV(%s) invalid CSV entry\n",lineSpec.c_str() );
return false;
}
double x = atof(values[0].c_str());
double y = atof(values[1].c_str());
double z = atof(values[2].c_str());
pageLocation = Base::Vector3d (x,y,z);
x = atof(values[3].c_str());
y = atof(values[4].c_str());
z = atof(values[5].c_str());
modelLocation = Base::Vector3d (x,y,z);
linkGeom = atoi(values[6].c_str());
color.fromHexString(values[7]);
size = atof(values[8].c_str());
style = atoi(values[9].c_str());
visible = atoi(values[10].c_str());
return true;
}
std::vector<std::string> CosmeticVertex::split(std::string csvLine)
{
Base::Console().Message("CV::split - csvLine: %s\n",csvLine.c_str());
std::vector<std::string> result;
std::stringstream lineStream(csvLine);
std::string cell;
while(std::getline(lineStream,cell, ','))
{
result.push_back(cell);
}
return result;
}
void CosmeticVertex::dump(char* title)
{
Base::Console().Message("CV::dump - %s \n",title);
Base::Console().Message("CV::dump - %s \n",toCSV().c_str());
}

View File

@@ -0,0 +1,58 @@
/***************************************************************************
* Copyright (c) 2019 WandererFan <wandererfan@gmail.com> *
* *
* 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 TECHDRAW_COSMETIC_H
#define TECHDRAW_COSMETIC_H
#include <Base/Vector3D.h>
#include <App/Material.h>
namespace TechDraw {
class TechDrawExport CosmeticVertex
{
public:
CosmeticVertex();
CosmeticVertex(Base::Vector3d loc);
virtual ~CosmeticVertex() = default;
std::string toCSV(void) const;
bool fromCSV(std::string& lineSpec);
void dump(char* title);
Base::Vector3d pageLocation;
Base::Vector3d modelLocation;
int linkGeom; //connection to corresponding "real" Vertex
App::Color color;
double size;
int style;
bool visible;
protected:
std::vector<std::string> split(std::string csvLine);
};
} //end namespace TechDraw
#endif //TECHDRAW_COSMETIC_H

View File

@@ -39,7 +39,6 @@
#include <Base/Console.h>
#include <Base/UnitsApi.h>
#include "DrawView.h"
#include "DrawPage.h"
#include "DrawViewCollection.h"
#include "DrawViewClip.h"
@@ -47,11 +46,15 @@
#include "DrawProjGroupItem.h"
#include "DrawLeaderLine.h"
#include "DrawUtil.h"
#include "Geometry.h"
#include "Cosmetic.h"
#include <Mod/TechDraw/App/DrawViewPy.h> // generated from DrawViewPy.xml
using namespace TechDraw;
#include "DrawView.h"
using namespace TechDraw;
using namespace TechDrawGeometry;
//===========================================================================
// DrawView
@@ -323,12 +326,6 @@ std::vector<TechDraw::DrawLeaderLine*> DrawView::getLeaders() const
return result;
}
void DrawView::addRandomVertex(Base::Vector3d pos)
{
(void) pos;
Base::Console().Message("DV::addRandomVertex()\n");
}
void DrawView::Restore(Base::XMLReader &reader)
{
// this is temporary code for backwards compat (within v0.17). can probably be deleted once there are no development

View File

@@ -38,6 +38,7 @@ namespace TechDraw
class DrawPage;
class DrawViewClip;
class DrawLeaderLine;
class CosmeticVertex;
/** Base class of all View Features in the drawing module
*/
@@ -90,8 +91,8 @@ public:
void requestPaint(void);
virtual void handleXYLock(void);
virtual bool isLocked(void) const;
virtual void addRandomVertex(Base::Vector3d pos);
std::vector<TechDraw::DrawLeaderLine*> getLeaders() const;
std::vector<TechDraw::DrawLeaderLine*> getLeaders(void) const;
protected:
virtual void onChanged(const App::Property* prop) override;

View File

@@ -102,7 +102,7 @@
#include "DrawPage.h"
#include "EdgeWalker.h"
#include "LineGroup.h"
#include "Cosmetic.h"
#include <Mod/TechDraw/App/DrawViewPartPy.h> // generated from DrawViewPartPy.xml
@@ -117,7 +117,9 @@ using namespace std;
PROPERTY_SOURCE(TechDraw::DrawViewPart, TechDraw::DrawView)
DrawViewPart::DrawViewPart(void) : geometryObject(0)
DrawViewPart::DrawViewPart(void) :
geometryObject(0),
on1(true)
{
static const char *group = "Projection";
static const char *sgroup = "HLR Parameters";
@@ -148,8 +150,16 @@ DrawViewPart::DrawViewPart(void) : geometryObject(0)
ADD_PROPERTY_TYPE(IsoHidden ,(false),sgroup,App::Prop_None,"Hidden Iso u,v lines on/off");
ADD_PROPERTY_TYPE(IsoCount ,(0),sgroup,App::Prop_None,"Number of isoparameters");
ADD_PROPERTY_TYPE(CosmeticVertexList ,(""),sgroup,App::Prop_None,"CosmeticVertex Save/Restore");
geometryObject = nullptr;
getRunControl();
// Base::Vector3d org(0.0,0.0,0.0); //App side coords
// addRandomVertex(org);
// Base::Vector3d pt(11.0,11.0,0.0);
// addRandomVertex(pt);
}
DrawViewPart::~DrawViewPart()
@@ -279,6 +289,13 @@ App::DocumentObjectExecReturn *DrawViewPart::execute(void)
if (!keepUpdated()) {
return App::DocumentObject::StdReturn;
}
//this is ghastly! but no convenient method for "object ready"
if (on1) {
rebuildCosmoVertex();
on1 = false;
}
App::Document* doc = getDocument();
bool isRestoring = doc->testStatus(App::Document::Status::Restoring);
const std::vector<App::DocumentObject*>& links = Source.getValues();
@@ -324,6 +341,13 @@ App::DocumentObjectExecReturn *DrawViewPart::execute(void)
Rotation.getValue());
}
geometryObject = buildGeometryObject(mirroredShape,viewAxis);
//add back the cosmetic vertices
Base::Console().Message("DVP::execute - cosmoVertex: %d \n",cosmoVertex.size());
for (auto& v: cosmoVertex) {
Base::Console().Message("DVP::execute - adding random vertex\n");
int idx = geometryObject->addRandomVertex(v->pageLocation * getScale());
v->linkGeom = idx;
}
#if MOD_TECHDRAW_HANDLE_FACES
auto start = chrono::high_resolution_clock::now();
@@ -380,7 +404,6 @@ short DrawViewPart::mustExecute() const
void DrawViewPart::onChanged(const App::Property* prop)
{
DrawView::onChanged(prop);
//TODO: when scale changes, any Dimensions for this View sb recalculated. DVD should pick this up subject to topological naming issues.
}
@@ -867,10 +890,34 @@ bool DrawViewPart::showSectionEdges(void)
return m_sectionEdges;
}
//build cosmoVertex from CosmeticVertexList
void DrawViewPart::rebuildCosmoVertex(void)
{
Base::Console().Message("DVP::rebuildCosmoVertx()\n");
cosmoVertex.clear();
std::vector<std::string> restoreVerts = CosmeticVertexList.getValues();
Base::Console().Message("DVP::rebuildCosmoVertex - verts in: %d \n",restoreVerts.size());
for (auto& rv: restoreVerts) {
if (!rv.empty()) {
CosmeticVertex* cv = new CosmeticVertex();
bool rc = cv->fromCSV(rv);
if (rc) {
// int idx = geometryObject->addRandomVertex(cv->pageLocation * getScale());
// cv->linkGeom = idx;
cosmoVertex.push_back(cv);
} else {
delete cv;
}
}
}
Base::Console().Message("DVP::rebuildCosmoVertex - cosmoVertexs: %d \n",cosmoVertex.size());
}
//! remove features that are useless without this DVP
//! hatches, geomhatches, dimensions,...
void DrawViewPart::unsetupObject()
{
Base::Console().Message("DVP::unsetupObject()\n");
nowUnsetting = true;
App::Document* doc = getDocument();
std::string docName = doc->getName();
@@ -924,7 +971,6 @@ void DrawViewPart::unsetupObject()
}
}
}
}
//! is this an Isometric projection?
@@ -939,6 +985,67 @@ bool DrawViewPart::isIso(void) const
return result;
}
//********
//* Cosmetics
//********
// adds a cosmetic vertex to cosmoVertex and CosmeticVertexList
int DrawViewPart::addRandomVertex(Base::Vector3d pos)
{
// Base::Console().Message("DVP::addRandomVertex(%s)\n", DrawUtil::formatVector(pos).c_str());
int newIdx = -1;
TechDraw::CosmeticVertex* rVert = new TechDraw::CosmeticVertex(pos);
cosmoVertex.push_back(rVert);
//stuff stringList
std::vector<std::string> saveVerts;
const std::vector<TechDraw::CosmeticVertex*> cosVerts = getCosmeticVertex();
for (auto& cv: cosVerts) {
std::string csv = cv->toCSV();
saveVerts.push_back(csv);
}
CosmeticVertexList.setValues(saveVerts);
Base::Console().Message("DVP::addRandomVertex - saveVerts: %d \n",saveVerts.size());
return newIdx;
}
TechDraw::CosmeticVertex* DrawViewPart::getCosmeticVertexByIndex(int idx) const
{
// Base::Console().Message("DVP::getCosmeticVertexByIndex(%d)\n", idx);
int cosmoOffset = 1000;
int realIdx = idx - cosmoOffset;
CosmeticVertex* result = nullptr;
const std::vector<TechDraw::CosmeticVertex*> verts = getCosmeticVertex();
if ((unsigned) realIdx < verts.size()) {
result = verts.at(realIdx);
}
return result;
}
//find the cosmetic vertex corresponding to geometry vertex idx
TechDraw::CosmeticVertex* DrawViewPart::getCosmeticVertexByLink(int idx) const
{
// Base::Console().Message("DVP::getVosmeticVertexByLinkIndex(%d)\n", idx);
CosmeticVertex* result = nullptr;
const std::vector<TechDraw::CosmeticVertex*> verts = getCosmeticVertex();
for (auto& cv: verts) {
if (cv->linkGeom == idx) {
result = cv;
break;
}
}
return result;
}
void DrawViewPart::clearCV(void)
{
Base::Console().Message("DVP::clearCV()\n");
cosmoVertex.clear();
std::vector<std::string> noVerts;
CosmeticVertexList.setValues(noVerts);
}
PyObject *DrawViewPart::getPyObject(void)
{
if (PythonObject.is(Py::_None())) {

View File

@@ -68,6 +68,7 @@ class DrawProjectSplit;
class DrawViewSection;
class DrawViewDetail;
class DrawViewBalloon;
class CosmeticVertex;
}
namespace TechDraw
@@ -101,6 +102,8 @@ public:
App::PropertyBool IsoHidden;
App::PropertyInteger IsoCount;
App::PropertyStringList CosmeticVertexList;
std::vector<TechDraw::DrawHatch*> getHatches(void) const;
std::vector<TechDraw::DrawGeomHatch*> getGeomHatches(void) const;
std::vector<TechDraw::DrawViewDimension*> getDimensions() const;
@@ -136,7 +139,7 @@ public:
const bool flip=true) const;
virtual short mustExecute() const;
/* virtual void onDocumentRestored() override;*/
// virtual void onDocumentRestored() override;
bool handleFaces(void);
bool showSectionEdges(void);
@@ -162,6 +165,12 @@ public:
virtual TopoDS_Shape getSourceShapeFused(void) const;
bool isIso(void) const;
virtual int addRandomVertex(Base::Vector3d pos);
const std::vector<TechDraw::CosmeticVertex*> & getCosmeticVertex(void) const { return cosmoVertex; }
TechDraw::CosmeticVertex* getCosmeticVertexByIndex(int idx) const;
TechDraw::CosmeticVertex* getCosmeticVertexByLink(int idx) const;
void clearCV(void);
protected:
TechDrawGeometry::GeometryObject *geometryObject;
Base::BoundBox3d bbox;
@@ -183,8 +192,13 @@ protected:
bool m_sectionEdges;
bool m_handleFaces;
//Cosmetics
std::vector<TechDraw::CosmeticVertex*> cosmoVertex;
void rebuildCosmoVertex(void);
private:
bool nowUnsetting;
bool on1;
/* bool m_restoreComplete;*/
};

View File

@@ -13,6 +13,11 @@
<Author Licence="LGPL" Name="WandererFan" EMail="wandererfan@gmail.com" />
<UserDocu>Feature for creating and manipulating Technical Drawing Part Views</UserDocu>
</Documentation>
<Methode Name="clearCV">
<Documentation>
<UserDocu>clearCV() - remove all CosmeticVertices from the View. Returns nothing.</UserDocu>
</Documentation>
</Methode>
<CustomAttributes />
</PythonExport>
</GenerateModel>

View File

@@ -15,6 +15,14 @@ std::string DrawViewPartPy::representation(void) const
return std::string("<DrawViewPart object>");
}
PyObject* DrawViewPartPy::clearCV(PyObject *args)
{
(void) args;
DrawViewPart* item = getDrawViewPartPtr();
item->clearCV();
Py_INCREF(Py_None);
return Py_None;
}
PyObject *DrawViewPartPy::getCustomAttributes(const char* /*attr*/) const
{

View File

@@ -67,11 +67,14 @@
#include <Base/Console.h>
#include <Base/Exception.h>
#include <Base/Tools2D.h>
#include <Base/Parameter.h>
#include <Mod/Part/App/Geometry.h>
#include <App/Application.h>
#include <App/Material.h>
#include "DrawUtil.h"
#include "Geometry.h"
#include "DrawUtil.h"
using namespace TechDrawGeometry;
using namespace TechDraw;
@@ -955,3 +958,5 @@ BaseGeomPtrVector GeometryUtils::chainGeoms(BaseGeomPtrVector geoms)
}
return result;
}

View File

@@ -472,6 +472,15 @@ void GeometryObject::addGeomFromCompound(TopoDS_Shape edgeCompound, edgeClass ca
} //end TopExp
}
int GeometryObject::addRandomVertex(Base::Vector3d pos)
{
// Base::Console().Message("GO::addRandomVertex(%s)\n",DrawUtil::formatVector(pos).c_str());
TechDrawGeometry::Vertex* v = new TechDrawGeometry::Vertex(pos.x, - pos.y);
vertexGeom.push_back(v);
int idx = vertexGeom.size() - 1;
return idx;
}
//! empty Face geometry
void GeometryObject::clearFaceGeom()
{

View File

@@ -125,6 +125,9 @@ public:
TopoDS_Shape getHidSeam(void) { return hidSeam; }
TopoDS_Shape getHidIso(void) { return hidIso; }
int addRandomVertex(Base::Vector3d pos);
protected:
//HLR output
TopoDS_Shape visHard;