1 #ifndef COIN_SOVECTORIZEACTION_H
2 #define COIN_SOVECTORIZEACTION_H
3 
4 /**************************************************************************\
5  * Copyright (c) Kongsberg Oil & Gas Technologies AS
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions are
10  * met:
11  *
12  * Redistributions of source code must retain the above copyright notice,
13  * this list of conditions and the following disclaimer.
14  *
15  * Redistributions in binary form must reproduce the above copyright
16  * notice, this list of conditions and the following disclaimer in the
17  * documentation and/or other materials provided with the distribution.
18  *
19  * Neither the name of the copyright holder nor the names of its
20  * contributors may be used to endorse or promote products derived from
21  * this software without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27  * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 \**************************************************************************/
35 
36 #include <Inventor/actions/SoCallbackAction.h>
37 #include <Inventor/actions/SoSubAction.h>
38 #include <Inventor/SbVec2f.h>
39 #include <Inventor/SbColor.h>
40 
41 class SoVectorOutput;
42 class SbViewportRegion;
43 class SoVectorizeItem;
44 class SoVectorizeActionP;
45 class SbBSPTree;
46 
47 // *************************************************************************
48 
49 class COIN_DLL_API SoVectorizeAction : public SoCallbackAction {
50   typedef SoCallbackAction inherited;
51 
52   SO_ACTION_HEADER(SoVectorizeAction);
53 
54 public:
55   SoVectorizeAction(void);
56   virtual ~SoVectorizeAction();
57 
58   SoVectorOutput * getOutput(void) const;
59 
60   static void initClass(void);
61 
62   enum DimensionUnit { INCH, MM, METER };
63   enum Orientation { PORTRAIT, LANDSCAPE };
64 
65   enum PageSize {
66     A0 = 0,
67     A1,
68     A2,
69     A3,
70     A4,
71     A5,
72     A6,
73     A7,
74     A8,
75     A9,
76     A10
77   };
78 
79   virtual void apply(SoNode * node);
80   virtual void apply(SoPath * path);
81   virtual void apply(const SoPathList & pathlist, SbBool obeysrules = FALSE);
82 
83   void beginStandardPage(const PageSize & pagesize, const float border = 10.0f);
84 
85   virtual void beginPage(const SbVec2f & startpagepos,
86                          const SbVec2f & pagesize,
87                          DimensionUnit u = MM);
88   virtual void endPage(void);
89 
90   virtual void calibrate(const SbViewportRegion & vp);
91 
92   virtual void beginViewport(const SbVec2f & startpos = SbVec2f(-1.0f, 1.0f),
93                              const SbVec2f & size = SbVec2f(-1.0f, -1.0f),
94                              DimensionUnit u = MM);
95   virtual void endViewport(void);
96 
97   virtual void setOrientation(Orientation o);
98   virtual Orientation getOrientation(void) const;
99 
100   virtual void setBackgroundColor(SbBool bg, const SbColor & col = SbColor(0.0f, 0.0f, 0.0f));
101   virtual SbBool getBackgroundColor(SbColor & col) const;
102 
103   virtual void setNominalWidth(float w, DimensionUnit u = MM);
104   virtual float getNominalWidth(DimensionUnit u = MM) const;
105 
106   virtual void setPixelImageSize(float w, DimensionUnit u = MM);
107   virtual float getPixelImageSize(DimensionUnit u = MM) const;
108 
109   enum PointStyle {
110     CIRCLE,
111     SQUARE
112   };
113 
114   virtual void setPointStyle(const PointStyle & style);
115   virtual PointStyle getPointStyle(void) const;
116 
117   const SbVec2f & getPageStartpos(void) const;
118   const SbVec2f & getPageSize(void) const;
119 
120 public:
121   // for TGS OIV compatibility. Might be implemented in the future
122   enum ColorTranslationMethod { REVERSE_ONLY_BLACK_AND_WHITE, AS_IS, REVERSE };
123 
124   enum JoinLineStyle { NO_JOIN, MITERED_JOIN, MITERED_BEVELED_JOIN,
125                        BEVELED_JOIN, TRIANGULAR_JOIN, ROUNDED_JOIN } ;
126   enum EndLineStyle { BUTT_END, SQUARE_END, TRIANGULAR_END, ROUND_END };
127   enum HLHSRMode { NO_HLHSR, HLHSR_SIMPLE_PAINTER, HLHSR_PAINTER,
128                    HLHSR_PAINTER_SURFACE_REMOVAL, HIDDEN_LINES_REMOVAL };
129 
130   virtual void setDrawingDimensions(const SbVec2f & d, DimensionUnit u = MM);
131   virtual void setDrawingDimensions(float w, float h, DimensionUnit u = MM) { this->setDrawingDimensions(SbVec2f(w, h), u); }
132   virtual SbVec2f getDrawingDimensions(DimensionUnit u = MM) const;
133 
134   virtual void setStartPosition(const SbVec2f & p, DimensionUnit u = MM);
135   virtual void setStartPosition(float x, float y, DimensionUnit u = MM) { this->setStartPosition(SbVec2f(x, y), u); }
136   virtual SbVec2f getStartPosition(DimensionUnit u = MM) const;
137 
138   virtual void setColorTranslationMethod(ColorTranslationMethod method);
139   virtual ColorTranslationMethod getColorTranslationMethod(void) const;
140 
141   virtual void setLineEndStyle(EndLineStyle style);
142   virtual EndLineStyle getLineEndStyle(void) const;
143 
144   virtual void setLineJoinsStyle(JoinLineStyle style);
145   virtual JoinLineStyle getLineJoinsStyle(void) const;
146 
147   virtual void setHLHSRMode(HLHSRMode mode);
148   HLHSRMode getHLHSRMode(void) const;
149 
150   virtual void setBorder(float width);
151   virtual void setBorder (float width, SbColor color);
152 
153   virtual void setMiterLimit(float limit);
154   virtual float getMiterLimit(void) const;
155 
156   virtual void setPenDescription(int num_pens,
157                                  const SbColor* colors = 0,
158                                  const float * widths = 0,
159                                  DimensionUnit u = MM);
160   virtual void getPenDescription(SbColor * colors,
161                                  float * widths,
162                                  DimensionUnit u = MM) const;
163   virtual int getPenNum(void) const;
164 
165   virtual void setColorPriority(SbBool priority);
166   virtual SbBool getColorPriority(void) const;
167 
168   virtual void enableLighting(SbBool flag);
169   SbBool isLightingEnabled(void) const;
170 
171 protected:
172   void setOutput(SoVectorOutput * output);
173 
174   virtual float pixelsToUnits(const int pixels);
175   virtual void printHeader(void) const = 0;
176   virtual void printFooter(void) const;
177   virtual void printBackground(void) const;
178   virtual void printItem(const SoVectorizeItem * item) const = 0;
179   virtual void printViewport(void) const;
180 
181   SbVec2f getRotatedViewportStartpos(void) const;
182   SbVec2f getRotatedViewportSize(void) const;
183 
184   const SbBSPTree & getBSPTree(void) const;
185 
186 private:
187   SoVectorizeActionP * pimpl;
188   friend class SoVectorizeActionP;
189 };
190 
191 // *************************************************************************
192 
193 #ifndef COIN_INTERNAL
194 // For SGI / TGS Open Inventor compile-time compatibility.
195 #include <Inventor/nodes/SoImage.h>
196 #endif // COIN_INTERNAL
197 
198 // *************************************************************************
199 
200 #endif // !COIN_SOVECTORIZEACTION_H
201