AssociativeElementAPI.h
Go to the documentation of this file.
1 /*--------------------------------------------------------------------------------------+
2 |
3 | Supplied under applicable software license agreement.
4 |
5 | Copyright (c) 2018 Bentley Systems, Incorporated. All rights reserved.
6 |
7 +---------------------------------------------------------------------------------------*/
8 #pragma once
10 SMARTFEATURE_TYPEDEFS(AssociativeCurveVector)
14 SMARTFEATURE_TYPEDEFS(AssociativeIntersection)
15 
16 #ifdef __SMARTFEATURE_BUILD__
17  #define SMARTFEATURE_EXPORT __declspec(dllexport)
18 #else
19  #define SMARTFEATURE_EXPORT __declspec(dllimport)
20 #endif
21 
22 #define ASSOCIATIVE_ELEMENT_VERSION 1
23 #define ELEMENTHANDLERID_AssociativeElementHandler 23006
25 typedef RefCountedPtr <struct AssociativeElement> AssociativeElementPtr;
26 typedef RefCountedPtr <struct AssociativeCurveVector> AssociativeCurveVectorPtr;
27 typedef RefCountedPtr <struct AssociativeOffsetFace> AssociativeOffsetFacePtr;
28 typedef RefCountedPtr <struct AssociativeFace> AssociativeFacePtr;
29 typedef RefCountedPtr <struct AssociativeEdge> AssociativeEdgePtr;
30 typedef RefCountedPtr <struct AssociativeIntersection> AssociativeIntersectionPtr;
31 //=======================================================================================
32 // AssociativeElement is a class used to create elements that will react to the changes
33 // of the parent element they are associated with. For example, extracting a face
34 // of a solid, and changing the solid, will cause the face to re-generate
35 //
36 // This is the base class for AssociativeElements and this should only be used to create
37 // new types of associative elements
38 //
39 // Both solid primitives and smart feature solids can be extracted with these elements
40 //
41 // How to use:
42 // 1. Create a desired associative element (e.g. AssociativeFace::Create(...))
43 // 2. Use AssociativeElement::CreateAssociativeElement (myNewEeh, &hostEh, destinationModel)
44 // this will intitialize your EditElementHandle to carry the XAttribute for the associative
45 // elements
46 // 3. Save the data of the new associative element in your EditElementHandle by calling
47 // AssociativeElement::SaveData(myNewEeh, associativeElementPtr)
48 // 4. Add myNewEeh to the model (e.g. myNewEeh.AddToModel())
49 //
50 // @bsistruct Diego.Pinate 04/17
51 //=======================================================================================
52 struct AssociativeElement : RefCountedBase
53 {
54 private:
55  static bmap<UInt32, IAssociativeElementFactory*> s_factories;
56 
57 protected:
58  virtual bool IsCurveVectorType() const { return false; }
59  virtual bool IsSurfaceType() const { return false; }
60 
64  SMARTFEATURE_EXPORT ElementHandle GetParentElement(ElementHandleCR hostEh, int index = 0) const
65  {
66  if (!m_peps[index].EvaluateElementFromHost(hostEh).IsValid())
67  {
68  //BeAssert(false && "\n --- Invalid parent element of Associative Element");
69  //BeConsole::Printf("\n Associative Element id = %d", hostEh.GetElementId());
70  }
71  return m_peps[index].EvaluateElementFromHost(hostEh);
72  }
73 
78  SMARTFEATURE_EXPORT static BentleyStatus ExtractData(AssociativeElementPtr& associativeElement, ElementHandleCR eh);
79 
84  SMARTFEATURE_EXPORT static BentleyStatus SaveData(EditElementHandleR eeh, AssociativeElementCR associativeElement);
85 
88 
93  SMARTFEATURE_EXPORT static void CreateAssociativeElement(EditElementHandleR newEeh, ElementHandleCP pTemplateEh, DgnModelRefP destinationModelRef);
94 }; // AssociativeElement
95 
96 //=======================================================================================
97 // Used to extract the face from a smart feature or solid primitive
98 // This type of element generates planar curve vectors only
99 // @bsistruct Diego.Pinate 04/17
100 //=======================================================================================
101 struct AssociativeFace : AssociativeCurveVector
102 {
103 public:
113  SMARTFEATURE_EXPORT static AssociativeElementPtr Create(ElementHandleCR hostEh, FaceId& faceId, UInt32 nodeId = 0) { return new AssociativeFace(hostEh, faceId, nodeId); };
114 }; // AssociativeFace
115 
116 //=======================================================================================
117 // Used to extract edges from a smart feature or solid primitive
118 // This type of element generates curve vectors only
119 // @bsistruct Diego.Pinate 04/17
120 //=======================================================================================
121 struct AssociativeEdge : AssociativeCurveVector
122 {
123 public:
133  SMARTFEATURE_EXPORT static AssociativeElementPtr Create(ElementHandleCR hostEh, bvector<EdgeId>& edgeIds, UInt32 nodeId = 0) { return new AssociativeEdge(hostEh, edgeIds, nodeId); };
134 }; // AssociativeEdge
135 
136 //=======================================================================================
137 // Used to generate an associative slice of a solid
138 // This base class will handle slicing and providing a curve vector
139 // Child classes should handle how to generate the slicing plane so that we can support
140 // Different types of inputs
141 // @bsistruct Diego.Pinate 06/17
142 //=======================================================================================
143 struct AssociativeSlice : AssociativeCurveVector
144 {
145  friend struct AssociativeElement;
146 
147  AssociativeSlice(UInt32 type) : AssociativeCurveVector(type) { }
148  AssociativeSlice(ElementHandleCR hostEh, UInt32 type, UInt32 nodeId) : AssociativeCurveVector(hostEh, type, nodeId) { }
149  AssociativeSlice(bvector<ElementHandle> const& dependents, bvector<UInt32> const& nodeIds, UInt32 type) : AssociativeCurveVector(dependents, nodeIds, type) { }
150 protected:
161  virtual BentleyStatus _ObtainPlane(ElementHandleCR hostEh, DPlane3dR plane) const { return ERROR; }
169 
170  virtual BentleyStatus _GenerateCurveVector(ElementHandleCR hostEh, CurveVectorPtr& curveVector) override;
171 };
172 
173 //=======================================================================================
174 // Used to slice a solid using the direction of a curve and the point as the plane
175 // @bsistruct Diego.Pinate 06/17
176 //=======================================================================================
178 {
179  friend struct AssociativeElement;
180 
181  enum Flags
182  {
183  USE_DISTANCE = 1 << 0,
184  };
185 
186 protected:
187  double m_fraction;
189 
190  virtual BentleyStatus _ExtractData(SmartFeatureDataSource& source) override;
191  virtual BentleyStatus _SaveData(SmartFeatureDataSink& sink) const override;
192  virtual BentleyStatus _ObtainPlane(ElementHandleCR hostEh, DPlane3dR plane) const override;
193 
194  bool IsDefinedByDistance() const { return ((m_flags & USE_DISTANCE) != 0); }
195 
196  virtual bool IsCurveVectorType() const override { return true; }
197  virtual bool IsSurfaceType() const override { return true; }
198 
199  AssociativeSliceOnCurve() : AssociativeSlice((UInt32)AssociativeElementType::SliceOnCurve) { }
200  AssociativeSliceOnCurve(bvector<ElementHandle> const& dependents, bvector<UInt32> const& nodeIds, double distance, UInt32 flags);
201 
202 public:
210  SMARTFEATURE_EXPORT static AssociativeElementPtr Create(ElementHandleCR solidEh, ElementHandleCR pathEh, double fractionOrDistance, UInt32 nodeId, UInt32 flags);
211 };
212 
213 //=======================================================================================
214 // Used to extract faces from solid primitives or smart features, they can be non-planar
215 // This type of element may generate curve vectors, bspline surfaces or solid primitive
216 // faces
217 // @bsistruct Diego.Pinate 04/17
218 //=======================================================================================
220 {
221 public:
222  double GetOffset () { return m_offset; }
223  void SetOffset(double offset) { m_offset = offset; }
224 
225 
233  SMARTFEATURE_EXPORT static AssociativeElementPtr Create(ElementHandleCR hostEh, FaceId id, UInt32 nodeId, UInt32 geomType, double offset = 0.0) { return new AssociativeOffsetFace(hostEh, id, nodeId,offset, geomType); }
234 
235 
236 }; // AssociativeOffsetFace
237 
238 public:
239  double GetOffset() { return m_offset; }
240  void SetOffset(double offset) { m_offset = offset; }
241 
242  SMARTFEATURE_EXPORT static AssociativeElementPtr Create(ElementHandleCR hostEh, FaceId id, UInt32 nodeId, double offset = 0.0) { return new AssociativeOffsetCurveVector(hostEh, id, nodeId, offset); }
243 };
244 
struct DPlane3d & DPlane3dR
Definition: msgeomstructs_typedefs.h:113
virtual BentleyStatus _ObtainSolidBody(ElementHandleCR hostEh, ISolidKernelEntityPtr &body)
Obtain the solid body that will be used to slice.
Definition: Bentley.h:212
BEGIN_SMARTFEATURE_NAMESPACE typedef RefCountedPtr< struct AssociativeElement > AssociativeElementPtr
Definition: AssociativeElementAPI.h:25
bool IsDefinedByDistance() const
Definition: AssociativeElementAPI.h:194
Definition: AssociativeElementAPI.h:143
static void CreateAssociativeElement(EditElementHandleR newEeh, ElementHandleCP pTemplateEh, DgnModelRefP destinationModelRef)
Initializes an EditElementHandle to have the XAttribute for associative elements. ...
Definition: AssociativeElementAPI.h:52
AssociativeSliceOnCurve()
Definition: AssociativeElementAPI.h:199
Definition: AssociativeElementAPI.h:183
RefCountedPtr< struct AssociativeOffsetFace > AssociativeOffsetFacePtr
Definition: AssociativeElementAPI.h:27
ElementHandle GetParentElement(ElementHandleCR hostEh, int index=0) const
Obtain the parent element used to extract this element.
Definition: AssociativeElementAPI.h:64
virtual BentleyStatus _ExtractData(SmartFeatureDataSource &source) override
Definition: AssociativeElementAPI.h:101
#define SMARTFEATURE_TYPEDEFS(t)
Definition: SmartFeatureBaseDefs.h:13
virtual BentleyStatus _ObtainPlane(ElementHandleCR hostEh, DPlane3dR plane) const override
double GetOffset()
Definition: AssociativeElementAPI.h:239
RefCountedPtr< ISolidKernelEntity > ISolidKernelEntityPtr
Reference counted type to manage the life-cycle of the ISolidKernelEntity.
Definition: SolidKernel.h:79
double m_fraction
Definition: AssociativeElementAPI.h:187
RefCountedPtr< struct CurveVector > CurveVectorPtr
Definition: GeomApi.h:113
virtual bool IsCurveVectorType() const
Definition: AssociativeElementAPI.h:58
RefCountedPtr< struct AssociativeIntersection > AssociativeIntersectionPtr
Definition: AssociativeElementAPI.h:30
double GetOffset()
Definition: AssociativeElementAPI.h:222
void SetOffset(double offset)
Definition: AssociativeElementAPI.h:240
#define SMARTFEATURE_EXPORT
Definition: AssociativeElementAPI.h:19
uint32_t UInt32
Definition: Bentley.r.h:128
RefCountedPtr< struct AssociativeEdge > AssociativeEdgePtr
Definition: AssociativeElementAPI.h:29
virtual BentleyStatus _SaveData(SmartFeatureDataSink &sink) const override
static bool IsAssociativeElement(ElementHandleCR eh)
AssociativeSlice(ElementHandleCR hostEh, UInt32 type, UInt32 nodeId)
Definition: AssociativeElementAPI.h:148
struct DgnPlatform::EditElementHandle & EditElementHandleR
Definition: DgnPlatform.h:254
static AssociativeElementPtr Create(ElementHandleCR hostEh, FaceId id, UInt32 nodeId, UInt32 geomType, double offset=0.0)
Creates an extracted face from a solid primitive or smart feature and sets an offset of the face this...
Definition: AssociativeElementAPI.h:233
virtual bool IsCurveVectorType() const override
Definition: AssociativeElementAPI.h:196
RefCountedPtr< struct AssociativeCurveVector > AssociativeCurveVectorPtr
Definition: AssociativeElementAPI.h:26
BentleyStatus
Definition: Bentley.h:208
virtual BentleyStatus _GenerateCurveVector(ElementHandleCR hostEh, CurveVectorPtr &curveVector) override
AssociativeSlice(bvector< ElementHandle > const &dependents, bvector< UInt32 > const &nodeIds, UInt32 type)
Definition: AssociativeElementAPI.h:149
Flags
Definition: AssociativeElementAPI.h:181
virtual BentleyStatus _ObtainPlane(ElementHandleCR hostEh, DPlane3dR plane) const
Obtain the plane used to slice the solid.
Definition: AssociativeElementAPI.h:161
struct DgnPlatform::ElementHandle const * ElementHandleCP
Definition: DgnPlatform.h:260
A Bentley supplied implementation std::vector.
Definition: stdcxx/bvector.h:77
AssociativeSlice(UInt32 type)
Definition: AssociativeElementAPI.h:147
void SetOffset(double offset)
Definition: AssociativeElementAPI.h:223
static AssociativeElementPtr Create(ElementHandleCR hostEh, bvector< EdgeId > &edgeIds, UInt32 nodeId=0)
Creates an extracted edge element from a solid or smart feature.
Definition: AssociativeElementAPI.h:133
virtual bool IsSurfaceType() const
Definition: AssociativeElementAPI.h:59
#define END_SMARTFEATURE_NAMESPACE
Definition: SmartFeatureBaseDefs.h:11
#define BEGIN_SMARTFEATURE_NAMESPACE
Definition: SmartFeatureBaseDefs.h:10
Definition: AssociativeElementAPI.h:219
RefCountedPtr< struct AssociativeFace > AssociativeFacePtr
Definition: AssociativeElementAPI.h:28
static AssociativeElementPtr Create(ElementHandleCR hostEh, FaceId &faceId, UInt32 nodeId=0)
Creates an extracted face element from a solid primitive or a smart feature.
Definition: AssociativeElementAPI.h:113
struct DgnPlatform::ElementHandle const & ElementHandleCR
Definition: DgnPlatform.h:260
Definition: AssociativeElementAPI.h:177
struct Bentley::faceId FaceId
{nodeId, entityId} pair for solid topology references.
virtual BentleyStatus _GetPlaneSheet(ElementHandleCR hostEh, ISolidKernelEntityPtr &sheetBody)
Calculates the plane sheet that will be used to slice the solid.
Definition: AssociativeElementAPI.h:121
UInt32 m_flags
Definition: AssociativeElementAPI.h:188
struct DgnPlatform::DgnModelRef * DgnModelRefP
Definition: DgnPlatform.h:223
static BentleyStatus ExtractData(AssociativeElementPtr &associativeElement, ElementHandleCR eh)
Extract an associative element from an ElementHandle where it resides.
static BentleyStatus SaveData(EditElementHandleR eeh, AssociativeElementCR associativeElement)
Saves the data of an associative element into an edit element handle.
static AssociativeElementPtr Create(ElementHandleCR solidEh, ElementHandleCR pathEh, double fractionOrDistance, UInt32 nodeId, UInt32 flags)
Creates an Associative Slice On Curve.
virtual bool IsSurfaceType() const override
Definition: AssociativeElementAPI.h:197

Copyright © 2017 Bentley Systems, Incorporated. All rights reserved.