KiCad PCB EDA Suite
Loading...
Searching...
No Matches
vrml_layer.h
Go to the documentation of this file.
1/*
2 * file: vrml_layer.h
3 *
4 * This program source code file is part of KiCad, a free EDA CAD application.
5 *
6 * Copyright (C) 2013-2017 Cirilo Bernardo
7 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 */
22
26
27/*
28 * Classes and structures to support the tesselation of a PCB for VRML output.
29 */
30
31#ifndef VRML_LAYER_H
32#define VRML_LAYER_H
33
34#include <iostream>
35#include <vector>
36#include <list>
37#include <utility>
38
39#include <wx/gdicmn.h>
40
41class GLUtesselator;
42
43typedef unsigned int GLenum;
44
45#ifndef M_PI2
46#define M_PI2 ( M_PI / 2.0 )
47#endif
48
49#ifndef M_PI4
50#define M_PI4 ( M_PI / 4.0 )
51#endif
52
53
55{
56 double x;
57 double y;
58 int i; // vertex index
59 int o; // vertex order
60 bool pth; // true for plate-through hole
61};
62
64{
65 int i1, i2, i3;
66
67 TRIPLET_3D( int p1, int p2, int p3 )
68 {
69 i1 = p1;
70 i2 = p2;
71 i3 = p3;
72 }
73};
74
75
77{
78public:
79 VRML_LAYER();
80 virtual ~VRML_LAYER();
81
89 void GetArcParams( int& aMaxSeg, double& aMinLength, double& aMaxLength );
90
101 bool SetArcParams( int aMaxSeg, double aMinLength, double aMaxLength );
102
106 void ResetArcParams();
107
111 void Clear( void );
112
116 int GetSize( void );
117
121 int GetNContours( void )
122 {
123 return contours.size();
124 }
125
132 int NewContour( bool aPlatedHole = false );
133
142 bool AddVertex( int aContourID, double aXpos, double aYpos );
143
152 bool EnsureWinding( int aContourID, bool aHoleFlag );
153
164 bool AppendCircle( double aXpos, double aYpos, double aRadius, int aContourID,
165 bool aHoleFlag = false );
166
177 bool AddCircle( double aXpos, double aYpos, double aRadius, bool aHoleFlag = false,
178 bool aPlatedHole = false );
179
192 bool AddSlot( double aCenterX, double aCenterY, double aSlotLength, double aSlotWidth,
193 double aAngle, bool aHoleFlag = false, bool aPlatedHole = false );
194
206 bool AppendArc( double aCenterX, double aCenterY, double aRadius, double aStartAngle,
207 double aAngle, int aContourID );
208
222 bool AddArc( double aCenterX, double aCenterY, double aStartX, double aStartY,
223 double aArcWidth, double aAngle, bool aHoleFlag = false,
224 bool aPlatedHole = false );
225
234 bool AddPolygon( const std::vector< wxRealPoint >& aPolySet, double aCenterX, double aCenterY,
235 double aAngle );
236
244 bool Tesselate( VRML_LAYER* holes = NULL, bool aHolesOnly = false );
245
254 bool WriteVertices( double aZcoord, std::ostream& aOutFile, int aPrecision );
255
265 bool Write3DVertices( double aTopZ, double aBottomZ, std::ostream& aOutFile, int aPrecision );
266
275 bool WriteIndices( bool aTopFlag, std::ostream& aOutFile );
276
286 bool Write3DIndices( std::ostream& aOutFile, bool aIncludePlatedHoles = false );
287
296 VERTEX_3D* AddExtraVertex( double aXpos, double aYpos, bool aPlatedHole );
297
304 void glStart( GLenum cmd );
305
312 void glPushVertex( VERTEX_3D* vertex );
313
318 void glEnd( void );
319
323 void SetGLError( GLenum error_id );
324
335 int Import( int start, GLUtesselator* aTesselator );
336
343 VERTEX_3D* GetVertexByIndex( int aPointIndex );
344
348 const std::string& GetError( void );
349
350 void SetVertexOffsets( double aXoffset, double aYoffset );
351
362 bool Get3DTriangles( std::vector< double >& aVertexList, std::vector< int >& aIndexPlane,
363 std::vector< int >& aIndexSide, double aTopZ, double aBotZ );
364
374 bool Get2DTriangles( std::vector< double >& aVertexList, std::vector< int > &aIndexPlane,
375 double aHeight, bool aTopPlane );
376
377
378private:
379 void clearTmp( void ); // clear ephemeral data used by the tesselation routine
380
381 // add a triangular facet (triplet) to the output index list
382 bool addTriplet( VERTEX_3D* p0, VERTEX_3D* p1, VERTEX_3D* p2 );
383
384 // retrieve a vertex given its index; the vertex may be contained in the
385 // vertices vector, extra_verts vector, or foreign VRML_LAYER object
386 VERTEX_3D* getVertexByIndex( int aPointIndex, VRML_LAYER* holes );
387
388 void processFan( void ); // process a GL_TRIANGLE_FAN list
389 void processStrip( void ); // process a GL_TRIANGLE_STRIP list
390 void processTri( void ); // process a GL_TRIANGLES list
391
392 void pushVertices( bool holes ); // push the internal vertices
393 bool pushOutline( VRML_LAYER* holes ); // push the outline vertices
394
395 // calculate number of sides on an arc (angle is in radians)
396 int calcNSides( double aRadius, double aAngle );
397
398 // returns the number of solid or hole contours
399 int checkNContours( bool holes );
400
401public:
403 bool Fault;
404
405private:
406 // Arc parameters
407 int maxArcSeg; // maximum number of arc segments in a small circle
408 double minSegLength; // min. segment length
409 double maxSegLength; // max. segment length
410
411 // Vertex offsets to work around a suspected GLU tesselator bug
412 double offsetX;
413 double offsetY;
414
415 bool fix; // when true, no more vertices may be added by the user
416 int idx; // vertex index (number of contained vertices)
417 int ord; // vertex order (number of ordered vertices)
418 std::vector<VERTEX_3D*> vertices; // vertices of all contours
419 std::vector<std::list<int>*> contours; // lists of vertices for each contour
420 std::vector<bool>pth; // indicates whether a 'contour' is a PTH or not
421 std::vector<bool>solid; // indicates whether a 'contour' is a solid or a hole
422 std::vector< double > areas; // area of the contours (positive if winding is CCW)
423 std::list<TRIPLET_3D> triplets; // output facet triplet list (triplet of ORDER values)
424 std::list<std::list<int>*> outline; // indices for outline outputs (index by ORDER values)
425 std::vector<int> ordmap; // mapping of ORDER to INDEX
426
427 std::string error; // error message
428
429 int hidx; // number of vertices in the holes
430 int eidx; // index for extra vertices
431 std::vector<VERTEX_3D*> extra_verts; // extra vertices added for outlines and facets
432 std::vector<VERTEX_3D*> vlist; // vertex list for the GL command in progress
433 VRML_LAYER* pholes; // pointer to another layer object used for tesselation;
434 // this object is normally expected to hold only holes
435
436 GLUtesselator* tess; // local instance of the GLU tesselator
437 GLenum glcmd; // current GL command type ( fan, triangle, tri-strip, loop )
438};
439
440#endif // VRML_LAYER_H
void GetArcParams(int &aMaxSeg, double &aMinLength, double &aMaxLength)
Retrieve the parameters used in calculating the number of vertices in an arc.
virtual ~VRML_LAYER()
std::vector< double > areas
Definition vrml_layer.h:422
bool AddSlot(double aCenterX, double aCenterY, double aSlotLength, double aSlotWidth, double aAngle, bool aHoleFlag=false, bool aPlatedHole=false)
Create and add a slot feature to the list of contours.
bool AddPolygon(const std::vector< wxRealPoint > &aPolySet, double aCenterX, double aCenterY, double aAngle)
Create an arbitrary polygon and adds it to the list of contours.
int Import(int start, GLUtesselator *aTesselator)
Inserts all contours into the given tesselator.
bool WriteIndices(bool aTopFlag, std::ostream &aOutFile)
Write out the vertex sets required to render a planar surface.
void ResetArcParams()
Reset the parameters used in calculating the number of vertices in an arc to default values.
std::vector< bool > solid
Definition vrml_layer.h:421
std::vector< std::list< int > * > contours
Definition vrml_layer.h:419
bool Tesselate(VRML_LAYER *holes=NULL, bool aHolesOnly=false)
Create a list of outline vertices as well as the vertex sets required to render the surface.
void glStart(GLenum cmd)
Invoked by the GLU tesselator callback to notify this object of the type of GL command which is appli...
double maxSegLength
Definition vrml_layer.h:409
bool SetArcParams(int aMaxSeg, double aMinLength, double aMaxLength)
Set the parameters used in calculating the number of vertices in an arc.
std::vector< VERTEX_3D * > extra_verts
Definition vrml_layer.h:431
std::vector< bool > pth
Definition vrml_layer.h:420
int GetNContours(void)
Definition vrml_layer.h:121
bool Fault
set to true when a fault is encountered during tesselation
Definition vrml_layer.h:403
void SetVertexOffsets(double aXoffset, double aYoffset)
bool Get3DTriangles(std::vector< double > &aVertexList, std::vector< int > &aIndexPlane, std::vector< int > &aIndexSide, double aTopZ, double aBotZ)
Allocate and populate the 3D vertex and index lists with triangular vertices which may be used for re...
bool Write3DIndices(std::ostream &aOutFile, bool aIncludePlatedHoles=false)
Write out the vertex sets required to render an extruded solid.
bool WriteVertices(double aZcoord, std::ostream &aOutFile, int aPrecision)
Write out the list of vertices required to render a planar surface.
bool EnsureWinding(int aContourID, bool aHoleFlag)
Check the winding of a contour and ensures that it is a hole or a solid depending on the value of.
double offsetX
Definition vrml_layer.h:412
void clearTmp(void)
bool addTriplet(VERTEX_3D *p0, VERTEX_3D *p1, VERTEX_3D *p2)
bool AddCircle(double aXpos, double aYpos, double aRadius, bool aHoleFlag=false, bool aPlatedHole=false)
Create a circular contour and adds it to the internal list.
bool AddArc(double aCenterX, double aCenterY, double aStartX, double aStartY, double aArcWidth, double aAngle, bool aHoleFlag=false, bool aPlatedHole=false)
Create a slotted arc and adds it to the internal list of contours.
int GetSize(void)
double offsetY
Definition vrml_layer.h:413
void SetGLError(GLenum error_id)
Set the error message according to the specified OpenGL error.
bool Get2DTriangles(std::vector< double > &aVertexList, std::vector< int > &aIndexPlane, double aHeight, bool aTopPlane)
Allocate and populate the 3D vertex and index lists with triangular vertices which may be used for re...
bool AppendCircle(double aXpos, double aYpos, double aRadius, int aContourID, bool aHoleFlag=false)
Add a circular contour to the specified (empty) contour.
std::string error
Definition vrml_layer.h:427
bool pushOutline(VRML_LAYER *holes)
bool Write3DVertices(double aTopZ, double aBottomZ, std::ostream &aOutFile, int aPrecision)
Write out the list of vertices required to render an extruded solid.
VERTEX_3D * getVertexByIndex(int aPointIndex, VRML_LAYER *holes)
VRML_LAYER * pholes
Definition vrml_layer.h:433
void processStrip(void)
double minSegLength
Definition vrml_layer.h:408
int checkNContours(bool holes)
void glEnd(void)
Invoked by the GLU tesselator callback to notify this object that the vertex list is complete and rea...
std::vector< int > ordmap
Definition vrml_layer.h:425
void processFan(void)
void processTri(void)
std::list< TRIPLET_3D > triplets
Definition vrml_layer.h:423
int NewContour(bool aPlatedHole=false)
Create a new list of vertices and returns an index to the list.
VERTEX_3D * AddExtraVertex(double aXpos, double aYpos, bool aPlatedHole)
Add an extra vertex as required by the GLU tesselator.
std::vector< VERTEX_3D * > vertices
Definition vrml_layer.h:418
std::list< std::list< int > * > outline
Definition vrml_layer.h:424
const std::string & GetError(void)
int calcNSides(double aRadius, double aAngle)
void glPushVertex(VERTEX_3D *vertex)
Invoked by the GLU tesselator callback; the supplied vertex is added to the internal list of vertices...
std::vector< VERTEX_3D * > vlist
Definition vrml_layer.h:432
GLUtesselator * tess
Definition vrml_layer.h:436
GLenum glcmd
Definition vrml_layer.h:437
bool AppendArc(double aCenterX, double aCenterY, double aRadius, double aStartAngle, double aAngle, int aContourID)
Add an arc to the specified contour.
void Clear(void)
Erase all data except for arc parameters.
void pushVertices(bool holes)
bool AddVertex(int aContourID, double aXpos, double aYpos)
Add a point to the requested contour.
VERTEX_3D * GetVertexByIndex(int aPointIndex)
Return a pointer to the requested vertex or NULL if no such vertex exists.
TRIPLET_3D(int p1, int p2, int p3)
Definition vrml_layer.h:67
double x
Definition vrml_layer.h:56
double y
Definition vrml_layer.h:57
unsigned int GLenum
Definition vrml_layer.h:43