CFx SDK Documentation 2024 SP0
Loading...
Searching...
No Matches
GiSelectionStyle.h
Go to the documentation of this file.
1
2// Copyright (C) 2002-2022, Open Design Alliance (the "Alliance").
3// All rights reserved.
4//
5// This software and its documentation and related materials are owned by
6// the Alliance. The software may only be incorporated into application
7// programs owned by members of the Alliance, subject to a signed
8// Membership Agreement and Supplemental Software License Agreement with the
9// Alliance. The structure and organization of this software are the valuable
10// trade secrets of the Alliance and its suppliers. The software is also
11// protected by copyright law and international treaty provisions. Application
12// programs incorporating this software must include the following statement
13// with their copyright notices:
14//
15// This application incorporates Open Design Alliance software pursuant to a license
16// agreement with Open Design Alliance.
17// Open Design Alliance Copyright (C) 2002-2022 by Open Design Alliance.
18// All rights reserved.
19//
20// By use of this software, its documentation or related materials, you
21// acknowledge and accept the above terms.
23
24#ifndef __ODGISELECTIONSTYLE_H__
25#define __ODGISELECTIONSTYLE_H__
26
27#include "TD_PackPush.h"
28
29#include "Gi/Gi.h"
30
37{
38 public:
43 {
44 protected:
47 public:
48 ColorMask() : m_transparency(255) {}
49
54 void setColor(const OdCmEntityColor &color) { m_color = color; }
58 const OdCmEntityColor &color() const { return m_color; }
59
64 void setTransparency(OdUInt8 transparency) { m_transparency = transparency; }
68 OdUInt8 transparency() const { return isVisible() ? OdUInt8(m_transparency) : 255; }
69
75 void setColor(const OdCmEntityColor &color, OdUInt8 transparency) { setColor(color); setTransparency(transparency); }
76
80 bool isVisible() const { return m_transparency < 255; }
84 bool isOpaque() const { return !m_transparency; }
85
89 void reset() { m_color = OdCmEntityColor(); m_transparency = 255; }
90
91 bool operator ==(const ColorMask &cm2) const
92 { return (transparency() == cm2.transparency()) && (!isVisible() || color() == cm2.color()); }
93 bool operator !=(const ColorMask &cm2) const
94 { return (transparency() != cm2.transparency()) || (isVisible() && color() != cm2.color()); }
95 };
100 {
101 protected:
103 {
104 kDrawElement = (1 << 0), // Enable displaying of edges/faces
105 kPatternElement = (1 << 1), // Apply classic highlighting pattern for edges/faces
106 kMaskElement = (1 << 2), // Apply color mask effect to edges/faces
107 // Global element flags
108 kGOnTopOfDepth = (1 << 3), // Display element on top of depth buffer
109 kGlobalFlags = kGOnTopOfDepth, // List of global flags
110 //
111 kLastElementStyleFlag = kGOnTopOfDepth
112 };
114 ColorMask m_colorMask; // Color mask effect properties
115 public:
116 ElementStyle() : m_nFlags(0) { }
117
122 void setVisible(bool bVisible) { SETBIT(m_nFlags, kDrawElement, bVisible); }
126 bool isVisible() const { return GETBIT(m_nFlags, kDrawElement); }
127
132 void enablePattern(bool bEnable) { SETBIT(m_nFlags, kPatternElement, bEnable); }
136 bool isPatternEnabled() const { return GETBIT(m_nFlags, kPatternElement); }
137
142 void enableColorMasking(bool bEnable) { SETBIT(m_nFlags, kMaskElement, bEnable); }
146 bool isColorMaskingEnabled() const { return GETBIT(m_nFlags, kMaskElement); }
147
151 const ColorMask &colorMask() const { return m_colorMask; }
155 ColorMask &colorMask() { return m_colorMask; }
156
160 bool isOnTopOfDepth() const { return GETBIT(m_nFlags, kGOnTopOfDepth); }
161
166 bool hasEffect() const { return isPatternEnabled() || (isColorMaskingEnabled() && colorMask().isVisible()); }
167
171 void setByDefault() { m_nFlags = kDrawElement; m_colorMask.reset(); }
175 void setAsDisabled() { m_nFlags = 0; m_colorMask.reset(); }
179 void setForStippling() { m_nFlags = kDrawElement | kPatternElement; m_colorMask.reset(); }
183 void setForColorMasking() { m_nFlags = kDrawElement | kMaskElement; m_colorMask.setColor(OdCmEntityColor(48, 115, 250), 140); }
184
185 bool operator ==(const ElementStyle &secStyle) const
186 { return ((m_nFlags & ~kGlobalFlags) == (secStyle.m_nFlags & ~kGlobalFlags)) && (m_colorMask == secStyle.m_colorMask); }
187 bool operator !=(const ElementStyle &secStyle) const
188 { return ((m_nFlags & ~kGlobalFlags) != (secStyle.m_nFlags & ~kGlobalFlags)) || (m_colorMask != secStyle.m_colorMask); }
189 };
197 class EdgeStyle : public ElementStyle
198 {
199 public:
203 enum Mode
204 {
205 kExistEdges, // Draw exist edges, if them enabled.
206 kIsolineEdges, // Draw isolines for 3d objects and exist edges for others.
207 kContourEdges // Draw contours for 3d objects and exist edges for others.
208 };
209 protected:
211 {
212 kDrawIsolines = (kLastElementStyleFlag << 1), // Draw isolines for 3d objects
213 kDrawContours = (kLastElementStyleFlag << 2) // Draw contours for 3d objects
214 };
215 OdInt32 m_lineWeightExtension; // Number of pixels for lineweight enlargement
216 public:
217 EdgeStyle() : m_lineWeightExtension(0) { }
218
223 void setMode(Mode edgeMode)
224 { switch (edgeMode) {
225 case kIsolineEdges: SETBIT_1(m_nFlags, kDrawIsolines); SETBIT_0(m_nFlags, kDrawContours); break;
226 case kContourEdges: SETBIT_0(m_nFlags, kDrawIsolines); SETBIT_1(m_nFlags, kDrawContours); break;
227 default: SETBIT_0(m_nFlags, kDrawIsolines | kDrawContours);
228 }
229 }
233 Mode mode() const
234 { if (GETBIT(m_nFlags, kDrawIsolines)) return kIsolineEdges;
235 if (GETBIT(m_nFlags, kDrawContours)) return kContourEdges;
236 return kExistEdges;
237 }
238
243 void setLineWeightExtension(OdInt32 nLwdExtension) { m_lineWeightExtension = nLwdExtension; }
247 OdInt32 lineWeightExtension() const { return m_lineWeightExtension; }
251 bool hasLineWeightExtension() const { return m_lineWeightExtension != 0; }
252
257 bool hasEffect() const { return ElementStyle::hasEffect() || hasLineWeightExtension() || (mode() != kExistEdges); }
258
262 void setByDefault() { ElementStyle::setByDefault(); m_lineWeightExtension = 0; }
266 void setAsDisabled() { ElementStyle::setAsDisabled(); m_lineWeightExtension = 0; }
270 void setForStippling() { ElementStyle::setForStippling(); m_lineWeightExtension = 0; }
275 void setForColorMasking() { ElementStyle::setForColorMasking(); m_colorMask.setTransparency(128);
276 m_nFlags |= kDrawIsolines; m_lineWeightExtension = 5; }
277
278 bool operator ==(const EdgeStyle &secStyle) const
279 { return ElementStyle::operator ==(secStyle) && (m_lineWeightExtension == secStyle.m_lineWeightExtension); }
280 bool operator !=(const EdgeStyle &secStyle) const
281 { return ElementStyle::operator !=(secStyle) || (m_lineWeightExtension != secStyle.m_lineWeightExtension); }
282 };
287 {
288 protected:
291 public:
295 EdgeStyle &edgeStyle() { return m_edgeStyle; }
299 const EdgeStyle &edgeStyle() const { return m_edgeStyle; }
300
304 FaceStyle &faceStyle() { return m_faceStyle; }
308 const FaceStyle &faceStyle() const { return m_faceStyle; }
309
313 bool isOnTopOfDepth() const
314 { return m_edgeStyle.isOnTopOfDepth() && m_faceStyle.isOnTopOfDepth(); }
315
319 bool isVisible() const { return m_edgeStyle.isVisible() || m_faceStyle.isVisible(); }
324 bool hasEffect() const { return m_edgeStyle.hasEffect() || m_faceStyle.hasEffect(); }
325
329 void setByDefault() { m_edgeStyle.setByDefault(); m_faceStyle.setByDefault(); }
333 void setAsDisabled() { m_edgeStyle.setAsDisabled(); m_faceStyle.setAsDisabled(); }
337 void setForStippling() { m_edgeStyle.setForStippling(); m_faceStyle.setForStippling(); }
342 void setForColorMasking() { m_edgeStyle.setForColorMasking(); m_faceStyle.setForColorMasking(); }
343
349 void setForColorMasking(const OdCmEntityColor &color, OdUInt8 transparency)
350 { setByDefault();
351 m_edgeStyle.enableColorMasking(true); m_edgeStyle.colorMask().setColor(color, transparency);
352 m_faceStyle.enableColorMasking(true); m_faceStyle.colorMask().setColor(color, transparency); }
353
354 bool operator ==(const StyleEntry &secStyle) const
355 { return (m_edgeStyle == secStyle.m_edgeStyle) && (m_faceStyle == secStyle.m_faceStyle); }
356 bool operator !=(const StyleEntry &secStyle) const
357 { return (m_edgeStyle != secStyle.m_edgeStyle) || (m_faceStyle != secStyle.m_faceStyle); }
358 };
359 protected:
360 StyleEntry m_styleEntry[4];
361 protected:
363 {
364 static OdUInt32 getIntFlags(const ElementStyle &elemStyle)
365 { return static_cast<const GIntAccessor &>(elemStyle).m_nFlags; }
367 { GIntAccessor &gStyle = static_cast<GIntAccessor &>(elemStyle);
368 const OdUInt32 flags = gStyle.m_nFlags & kGlobalFlags; gStyle.m_nFlags &= ~kGlobalFlags;
369 return flags; }
370 static void installIntFlags(ElementStyle &elemStyle, OdUInt32 flags)
371 { GIntAccessor &gStyle = static_cast<GIntAccessor &>(elemStyle);
372 gStyle.m_nFlags = (gStyle.m_nFlags & ~kGlobalFlags) | flags; }
373 static bool isOnTopOfDepth(OdUInt32 flags) { return GETBIT(flags, kGOnTopOfDepth); }
374 static void setOnTopOfDepth(OdUInt32 &flags, bool bSet) { SETBIT(flags, kGOnTopOfDepth, bSet); }
375 };
376 class WrapGIntFlags { StyleEntry *m_pStyle; OdUInt32 m_flags[2];
377 public: WrapGIntFlags(StyleEntry &style, bool bWrap = true) : m_pStyle(bWrap ? &style : NULL)
378 { if (m_pStyle) { m_flags[0] = GIntAccessor::extractIntFlags(style.edgeStyle());
379 m_flags[1] = GIntAccessor::extractIntFlags(style.faceStyle()); } }
380 ~WrapGIntFlags() { if (m_pStyle) { GIntAccessor::installIntFlags(m_pStyle->edgeStyle(), m_flags[0]);
381 GIntAccessor::installIntFlags(m_pStyle->faceStyle(), m_flags[1]); } }
382 };
383 int makeEntryId(bool bDrawOnTop, bool bDrawIn3d) const { return ((bDrawOnTop) ? 1 : 0) | ((bDrawIn3d) ? 2 : 0); }
384 public:
386
392 StyleEntry &styleFor(bool bDrawOnTop = false, bool bDrawIn3d = false)
393 { return m_styleEntry[makeEntryId(bDrawOnTop, bDrawIn3d)]; }
399 const StyleEntry &styleFor(bool bDrawOnTop = false, bool bDrawIn3d = false) const
400 { return m_styleEntry[makeEntryId(bDrawOnTop, bDrawIn3d)]; }
401
405 void sync3d() { WrapGIntFlags _wint(styleFor(true, true));
406 styleFor(false, true) = styleFor(false, false); styleFor(true, true) = styleFor(true, false); }
410 void sync2d() { WrapGIntFlags _wint(styleFor(true, true));
411 styleFor(false, false) = styleFor(false, true); styleFor(true, false) = styleFor(true, true); }
412
418 void exchangeTopBottom(bool bFor2d = true, bool bFor3d = true)
419 { StyleEntry tmpEntry; WrapGIntFlags _wint(styleFor(true, true), bFor3d);
420 if (bFor2d) { tmpEntry = styleFor(false, false); styleFor(false, false) = styleFor(true, false); styleFor(true, false) = tmpEntry; }
421 if (bFor3d) { tmpEntry = styleFor(false, true); styleFor(false, true) = styleFor(true, true); styleFor(true, true) = tmpEntry; }
422 }
423
428 void setOnTopOfDepth(bool bSet) { StyleEntry &ent = styleFor(true, true);
429 OdUInt32 flags = GIntAccessor::getIntFlags(ent.edgeStyle()); GIntAccessor::setOnTopOfDepth(flags, bSet); GIntAccessor::installIntFlags(ent.edgeStyle(), flags);
430 flags = GIntAccessor::getIntFlags(ent.faceStyle()); GIntAccessor::setOnTopOfDepth(flags, bSet); GIntAccessor::installIntFlags(ent.faceStyle(), flags);
431 }
435 bool isOnTopOfDepth() const { return styleFor(true, true).isOnTopOfDepth(); }
436
440 void setByDefault() { styleFor(false).setByDefault(); styleFor(true).setAsDisabled(); sync3d(); }
444 void setAsDisabled() { styleFor(false).setAsDisabled(); styleFor(true).setAsDisabled(); sync3d(); }
449 void setForStippling() { styleFor(false).setForStippling(); styleFor(true).setAsDisabled(); sync3d(); }
454 void setForColorMasking() { styleFor(false).setByDefault(); styleFor(false).edgeStyle().setMode(EdgeStyle::kIsolineEdges);
455 styleFor(true).setForColorMasking(); sync3d(); }
456};
457
458#include "TD_PackPop.h"
459
460#endif //__ODGISELECTIONSTYLE_H__
bool operator!=(T left, const OdGiVariant::EnumType right)
Definition: GiVariant.h:403
bool operator==(T left, const OdGiVariant::EnumType right)
Definition: GiVariant.h:397
unsigned int OdUInt32
int OdInt32
unsigned char OdUInt8
#define SETBIT(flags, bit, value)
Definition: OdaDefs.h:516
#define SETBIT_0(flags, bit)
Definition: OdaDefs.h:519
#define GETBIT(flags, bit)
Definition: OdaDefs.h:517
#define SETBIT_1(flags, bit)
Definition: OdaDefs.h:520
#define FIRSTDLL_EXPORT
Definition: RootExport.h:39
const OdCmEntityColor & color() const
void setTransparency(OdUInt8 transparency)
void setColor(const OdCmEntityColor &color)
void setColor(const OdCmEntityColor &color, OdUInt8 transparency)
void setLineWeightExtension(OdInt32 nLwdExtension)
const ColorMask & colorMask() const
bool isVisible() const
EdgeStyle m_edgeStyle
bool hasEffect() const
FaceStyle & faceStyle()
void setAsDisabled()
void setForStippling()
EdgeStyle & edgeStyle()
const FaceStyle & faceStyle() const
bool isOnTopOfDepth() const
void setByDefault()
const EdgeStyle & edgeStyle() const
FaceStyle m_faceStyle
void setForColorMasking()
void setForColorMasking(const OdCmEntityColor &color, OdUInt8 transparency)
WrapGIntFlags(StyleEntry &style, bool bWrap=true)
void setOnTopOfDepth(bool bSet)
bool isOnTopOfDepth() const
int makeEntryId(bool bDrawOnTop, bool bDrawIn3d) const
void exchangeTopBottom(bool bFor2d=true, bool bFor3d=true)
ElementStyle FaceStyle
const StyleEntry & styleFor(bool bDrawOnTop=false, bool bDrawIn3d=false) const
StyleEntry & styleFor(bool bDrawOnTop=false, bool bDrawIn3d=false)
static void installIntFlags(ElementStyle &elemStyle, OdUInt32 flags)
static void setOnTopOfDepth(OdUInt32 &flags, bool bSet)
static OdUInt32 getIntFlags(const ElementStyle &elemStyle)
static OdUInt32 extractIntFlags(ElementStyle &elemStyle)
static bool isOnTopOfDepth(OdUInt32 flags)