SUAPI-CppWrapper
C++WrapperforSketchUpCAPI
Entities.hpp
1 //
2 // Entities.hpp
3 //
4 // Sketchup C++ Wrapper for C API
5 // MIT License
6 //
7 // Copyright (c) 2017 Tom Kaneko
8 //
9 // Permission is hereby granted, free of charge, to any person obtaining a copy
10 // of this software and associated documentation files (the "Software"), to deal
11 // in the Software without restriction, including without limitation the rights
12 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 // copies of the Software, and to permit persons to whom the Software is
14 // furnished to do so, subject to the following conditions:
15 
16 // The above copyright notice and this permission notice shall be included in all
17 // copies or substantial portions of the Software.
18 
19 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 // SOFTWARE.
26 //
27 
28 #ifndef Entities_hpp
29 #define Entities_hpp
30 
31 #include <stdio.h>
32 #include <vector>
33 
34 #include <SketchUpAPI/model/entities.h>
35 
36 #include "SUAPI-CppWrapper/String.hpp"
37 
38 namespace CW {
39 
40 // Forward declarations
41 class Model;
42 class Entity;
43 class Edge;
44 class Face;
45 class ComponentInstance;
46 class Group;
47 class ComponentDefinition;
48 class GeometryInput;
49 class Transformation;
50 class String;
51 class BoundingBox3D;
52 
53 /*
54 * Entities wrapper
55 */
56 class Entities {
57  private:
58  SUEntitiesRef m_entities;
59  // Store associated model ref, for type checking purposes
60  SUModelRef m_model;
61 
62  public:
63  /**
64  * Default constructor.
65  * @param model - SUModelRef object that this entities object resides in. Used for checking that entities added to the entities object is valid for adding to this model.
66  */
67  Entities(SUEntitiesRef entities, const SUModelRef model);
68 
69  /**
70  * Null Entities object
71  */
72  Entities();
73 
74  /**
75  * Fills an Entities object with geometry in GeometryInput object.
76  */
77  SUResult fill(GeometryInput &geom_input);
78 
79  std::vector<Face> faces() const;
80  std::vector<Edge> edges(bool stray_only = true) const;
81  std::vector<ComponentInstance> instances() const;
82  std::vector<Group> groups() const;
83 
84  /**
85  * Return the BoundingBox of the Entities object.
86  */
88 
89  /**
90  * Returns the number of entities that exist in the entities object.
91  */
92  size_t size() const;
93 
94  /**
95  * Adds the contents of an entities object into this one.
96  */
97  void add(const Entities& other);
98 
99  /*
100  * Creates faces in the Entities object.
101  *
102  * Note that this function does not merge overlapping geometry. See GeometryInput for merging functionality.
103  * @param vector of Face objects from CW
104  */
105  std::vector<Face> add_faces(std::vector<Face>& faces);
106  Face add_face(Face& face);
107 
108  /*
109  * Creates edges in the Entities object.
110  *
111  * Note that this function does not merge overlapping geometry. @see GeometryInput and Entities::fill() for merging functionality.
112  * @param vector of Edge objects to add
113  */
114  std::vector<Edge> add_edges(std::vector<Edge>& edges);
115  Edge add_edge(Edge& edge);
116 
117  /*
118  * Creates a ComponentInstance in the Entities object.
119  * @param instance ComponentInstance object to add to the Entities object.
120  */
121  void add_instance(ComponentInstance& instance);
122 
123  /*
124  * Creates a ComponentInstance in the Entities object.
125  * @param definition ComponentDefinition object to create an instance of
126  * @param transformation transformation of the definition (placement, rotation and scale)
127  */
128  ComponentInstance add_instance(const ComponentDefinition& definition, const Transformation& transformation, const String& name = "");
129 
130  /*
131  * Creates a Group in the Entities object.
132  * @param definition ComponentDefinition object to create an group of
133  * @param transformation transformation of the definition (placement, rotation and scale)
134  */
135  // TODO: this needs to be revised.
136  Group add_group(const ComponentDefinition& definition, const Transformation& transformation);
137  Group add_group();
138 
139 
140  /**
141  * Transforms given entities by the transformation object
142  * @since SketchUp 2017, API 5.0
143  * @param elems - vector array of Entity objects
144  * @param transform - the transformation to apply to the elements.
145  * @return true if the operation was successful. false, if transform failed.
146  */
147  bool transform_entities(std::vector<Entity>& elems, const Transformation& transform);
148 
149  /**
150  * Transforms given entities each by their transformation objects.
151  * @param elems - vector array of Entity objects
152  * @param transforms - the vector array of transformations to apply to the elements. The number of Transformation objects must match the number of elements given.
153  * @return true if the operation was successful. false, if transform failed.
154  */
155  bool transform_entities(std::vector<Entity>& elems, std::vector<Transformation>& transforms);
156 
157  /**
158  * Returns the model object that conrtains this entities object.
159  */
160  Model model() const;
161 
162  /*
163  * The class object can be converted to a SUEntitiesRef without loss of data.
164  */
165  operator SUEntitiesRef();
166 
167 };
168 
169 } /* namespace CW */
170 #endif /* Entities_hpp */
Model model() const
Definition: Entities.cpp:449
bool transform_entities(std::vector< Entity > &elems, const Transformation &transform)
Definition: Entities.cpp:413
size_t size() const
Definition: Entities.cpp:160
SUResult fill(GeometryInput &geom_input)
Definition: Entities.cpp:209
BoundingBox3D bounding_box() const
Definition: Entities.cpp:149
Definition: Color.hpp:34
void add(const Entities &other)
Definition: Entities.cpp:185