SUAPI-CppWrapper
C++WrapperforSketchUpCAPI
ComponentDefinition.hpp
1 //
2 // ComponentDefinition.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 ComponentDefinition_hpp
29 #define ComponentDefinition_hpp
30 
31 #include <stdio.h>
32 
33 #include <SketchUpAPI/model/component_definition.h>
34 
35 #include "SUAPI-CppWrapper/model/DrawingElement.hpp"
36 
37 namespace CW {
38 
39 // Forward declarations:
40 class Entities;
41 class ComponentInstance;
42 class Group;
43 class Behavior;
44 class String;
45 class Model;
46 class Opening;
47 
48 /**
49 * This class represents a component definition.
50 */
52  private:
53 
54  static SUComponentDefinitionRef create_definition();
55 
56  /**
57  * Copies a ComponentDefinition object into a new SUComponentDefinitionRef. If the other ComponentDefinition object has been attached to a model already, it will return the same SUComponentDefinitionRef object that it points to.
58  */
59  static SUComponentDefinitionRef copy_reference(const ComponentDefinition& other);
60 
61  public:
62  /**
63  * Constructor creates empty Component Definition, ready to add to a model.
64  */
66 
67  /**
68  * Constructor creates Component Definition from existing SUComponentDefinitionRef.
69  */
70  ComponentDefinition(SUComponentDefinitionRef definition, bool attached = true);
71 
72  /**
73  * Copy constructor.
74  */
76 
77  /**
78  * Destructor will release the definition object if it had not been added to a model.
79  */
81 
82  /** Copy assignment operator */
84 
85  /** Cast to native objects */
86  /**
87  * Returns the SUComponentDefinitionRef that this class wraps.
88  */
89  SUComponentDefinitionRef ref() const;
90  operator SUComponentDefinitionRef() const;
91  operator SUComponentDefinitionRef*();
92 
93  /**
94  * Creates a new ComponentInstance from this ComponentDefinition.
95  */
97 
98  /**
99  * Creates a new Group from this ComponentDefinition. If the definition is not a Group definition, the method will fail. TODO: requires testing
100  *
101  * This method is not possible to implement with the current API (2017)
102  */
103  //Group create_group() const;
104 
105  /**
106  * Gets the entities in the definition.
107  */
108  Entities entities() const;
109 
110  /**
111  * Gets the name of the component.
112  */
113  String name() const;
114 
115  /**
116  * Sets the name of the component.
117  */
118  bool name(String name);
119 
120  /**
121  * Returns whether this definition is of a group.
122  */
123  bool is_group() const;
124 
125  /**
126  * Returns the Behavior object of this component.
127  */
128  Behavior behavior() const;
129  void behavior(const Behavior& behavior) const;
130 
131  /**
132  * Retrieves the total number of instances of the provided definition. This method takes into account the full hierarchy of the model. Therefore, the count is influenced by adding/removing instances of other definitions which contain an instance of this definition. Users should not use this function to determine the count to be passed to SUComponentDefinitionGetInstances specifying the number of instances to be retrieved.
133  */
134  size_t num_used_instances() const;
135 
136  /**
137  * Retrieves the number of unique instances of the provided definition. The returned count represents the number of instances of this definition in the model's root plus the number instances of this definition contained in other definitions.
138  */
139  size_t num_instances() const;
140 
141  /**
142  * Returns the instances of this ComponentDefinition.
143  */
144  std::vector<ComponentInstance> instances() const;
145 
146  /**
147  * Retrieves the number of openings from the component definition.
148  * @since SketchUp 2016, API 4.0
149  **/
150  size_t num_openings() const;
151 
152  /**
153  * Retrieves the openings from the component definition.
154  * @since SketchUp 2016, API 4.0
155  **/
156  std::vector<Opening> openings() const;
157 
158 };
159 
160 class Behavior {
161 private:
162  SUComponentBehavior m_behavior;
163 
164 public:
165  Behavior(SUComponentBehavior behavior);
166 
167  SUComponentBehavior::SUSnapToBehavior &snap = m_behavior.component_snap;
168 
169  SUComponentBehavior ref() const;
170 
171  bool &cuts_opening = m_behavior.component_cuts_opening;
172 
173  bool &always_face_camera = m_behavior.component_always_face_camera;
174 
175  bool &shadows_face_sun = m_behavior.component_shadows_face_sun;
176 
177  size_t &no_scale_mask = m_behavior.component_no_scale_mask;
178 };
179 
180 } /* namespace CW */
181 #endif /* ComponentDefinition_hpp */
ComponentInstance create_instance() const
SUComponentDefinitionRef ref() const
std::vector< Opening > openings() const
bool attached() const
Returns true if the entity is attached to another object.
Definition: Entity.cpp:100
Definition: Color.hpp:34
ComponentDefinition & operator=(const ComponentDefinition &other)
std::vector< ComponentInstance > instances() const