SHAPER 9.16.0
PartSet_PreviewSketchPlane.h
1// Copyright (C) 2014-2026 CEA, EDF
2//
3// This library is free software; you can redistribute it and/or
4// modify it under the terms of the GNU Lesser General Public
5// License as published by the Free Software Foundation; either
6// version 2.1 of the License, or (at your option) any later version.
7//
8// This library is distributed in the hope that it will be useful,
9// but WITHOUT ANY WARRANTY; without even the implied warranty of
10// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11// Lesser General Public License for more details.
12//
13// You should have received a copy of the GNU Lesser General Public
14// License along with this library; if not, write to the Free Software
15// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16//
17// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18//
19
20#ifndef PartSet_PreviewSketchPlane_H
21#define PartSet_PreviewSketchPlane_H
22
23#include <memory>
24#include <utility>
25#include <Standard_Handle.hxx>
26#include <Aspect_GridType.hxx>
27#include <Aspect_GridDrawMode.hxx>
28#include <ModelAPI_CompositeFeature.h>
29#include <gp_Ax3.hxx>
30
31#include "PartSet_Tools.h"
32
36class GeomAPI_Face;
37class AIS_PlaneTrihedron;
38class V3d_Viewer;
39class QString;
40class gp_Trsf;
41
42// #define SKETCH_ACCESSORY_DBG;
43
51{
52public:
53 inline static bool SketchAccessoryDbg()
54 {
55#ifdef SKETCH_ACCESSORY_DBG
56 return true;
57#else
58 return false;
59#endif
60 };
61
62 static bool SketchAccessoryDbg(const QString& theString);
63 static bool SketchAccessoryDbg(const char* theString);
64 static bool SketchAccessoryDbg(const char* theCSDescription, const gp_Ax3& theCS);
65 static bool SketchAccessoryDbg(const char* theCSDescription, const gp_Pnt& thePoint);
66 static bool SketchAccessoryDbg(const char* theCSDescription, const gp_Trsf& theMatrix);
67
68 enum GridSnappingMode {
69 Off,
70 SnapAnyway,
71 SnapInProximity
72 };
73
79
80 void savePreferencesIntoSketchData(std::shared_ptr<ModelAPI_CompositeFeature> theSketch) const;
81 void saveRectangularGridPreferencesIntoSketchData(std::shared_ptr<ModelAPI_CompositeFeature> theSketch) const;
82 void saveCircularGridPreferencesIntoSketchData(std::shared_ptr<ModelAPI_CompositeFeature> theSketch) const;
83
85 void setCSAndSize(const gp_Ax3& theCS, double theSize);
86
92 bool setAllUsingSketch(std::shared_ptr<ModelAPI_CompositeFeature> theSketch);
93
97 bool reconfigureGrid();
98
104 bool reconfigureGridUsingSketch(std::shared_ptr<ModelAPI_CompositeFeature> theSketch);
105
107 bool showAxes(bool theShow);
109 bool showSubstrate(bool theShow);
112 bool setGridType(PartSet_Tools::SketchPlaneGridType::Enum theType);
113
114 PartSet_Tools::SketchPlaneGridType::Enum getGridType() const { return myGridType; }
115
117 void hideAll();
118
120 std::pair<double, double> getDimensions() const;
121
122 bool isShowAxes() const { return myShowTrihedron; }
123 bool isShowSubstrate() const { return myShowSubstrate; }
124 bool isShowGrid() const { return myGridType != PartSet_Tools::SketchPlaneGridType::No; }
125
126 GridSnappingMode getGridSnappingMode() const { return mySnappingMode; };
127 void setGridSnappingMode(GridSnappingMode theMode) { mySnappingMode = theMode; };
128
131
132 void setRectangularGridStepX(double theStepX);
133 void setRectangularGridStepY(double theStepY);
134 std::pair<double, double> getRectangularGridSteps() const { return myRectangularGridSteps; }
135
136 void setRectangularGridOffsetX(double theOffsetX);
137 void setRectangularGridOffsetY(double theOffsetY);
138 void setRectangularGridOffsetA(double theOffsetAngle);
139 std::pair<std::pair<double, double>, double> getRectangularGridOffsets() const;
140 int getRectangularGridDimOfNodeSpace() const { return myRectangularGridDimOfNodeSpace; }
141
143 void resetCircularGrid();
144
145 void setCircularGridRadialStep(double theStep);
146 void setCircularGridNumOfAngularSegments(int theNum);
147 std::pair<double, int> getCircularGrid_dR_and_NAS() const;
148
149 void setCircularGridOffsetX(double theOffset);
150 void setCircularGridOffsetY(double theOffset);
151 void setCircularGridOffsetA(double theOffset);
152 std::pair<std::pair<double, double>, double> getCircularGridOffsets() const;
153 int getCircularGridDimOfNodeSpace() const { return myCircularGridDimOfNodeSpace; }
154
155 void setUseSizeOfView(const bool isUseSizeOfView) { myIsUseSizeOfView = isUseSizeOfView; }
156 bool isUseSizeOfView() const { return myIsUseSizeOfView; }
157
158private:
159 void configureTrihedron();
160 void initSubstrate(std::shared_ptr<GeomAPI_Face> theFace);
161
162 opencascade::handle<V3d_Viewer> getV3DViewer() const;
163 bool isValid() const;
164 void setInvalid();
165
167 double getDefaultSize() const;
168
169 double getCircularGridRaduis(const std::pair<double, double>& theBBox2Dimensions) const;
170
173 static std::pair<double, double> dimsOfRectangleFittingRectangle(double wInner, double hInner, double angle, double cX, double cY);
174
175public:
177 static double defaultSketchSize();
178
179 static const double DEFAULT_RELATIVE_STEP_INVERSE;
180 static const int DEFAULT_NUM_OF_ANGULAR_SECTIONS;
181 static const int SNAP_PROXIMITY_P;
182
183private:
185 static const double DEFAULT_SKETCH_SIZE;
186
187 const PartSet_SketcherMgr* const mySketcherMgr;
188
189 bool myValid;
190 gp_Ax3 mySketchCS;
191 std::pair<double, double> mySketchDimensions; // Width and height of sketch bounding box, aligned with sketch axes.
192 double mySketchDefaultSize;
193 bool myIsUseSizeOfView = false;
194
195 bool myShowTrihedron;
196 opencascade::handle<AIS_PlaneTrihedron> myTrihedron; // Visualization of sketch axes and origin.
197
198 bool myShowSubstrate;
199 std::shared_ptr<GeomAPI_AISObject> mySubstrate; // Translucent substrate.
200
201 PartSet_Tools::SketchPlaneGridType::Enum myGridType;
202 Aspect_GridDrawMode myGridDrawMode;
203 GridSnappingMode mySnappingMode;
204
205 std::pair<double, double> myRectangularGridSteps;
206 std::pair<double, double> myRectangularGridTransOffset;
207 double myRectangularGridOffsetAngle;
208 int myRectangularGridDimOfNodeSpace; // Minimal dimension of space which can fit displayed grid nodes.
209
210 double myCircularGridRadialStep;
211 int myCircularGridNumOfAngularSections;
212 std::pair<double, double> myCircularGridTransOffset;
213 double myCircularGridOffsetAngle;
214 int myCircularGridDimOfNodeSpace; // Minimal dimension of space which can fit displayed grid nodes.
215};
216
217#endif
Interface for AIS_InteractiveObject.
Definition: GeomAPI_AISObject.h:39
Interface to the face object.
Definition: GeomAPI_Face.h:36
Feature that consists of other features: like sketcher with edges inside.
Definition: ModelAPI_CompositeFeature.h:33
Visualization of 2D-bluebrint' accessories: translucent rectangular substrate, basis axes,...
Definition: PartSet_PreviewSketchPlane.h:51
bool reconfigureGrid()
Call it, after any preference of grid, except grid type, is changed using methods of this instance....
Definition: PartSet_PreviewSketchPlane.cpp:395
bool setGridType(PartSet_Tools::SketchPlaneGridType::Enum theType)
Changes grid type and reconfigures grid. Shows grid, if theType != SketchPlaneGridType::No.
Definition: PartSet_PreviewSketchPlane.cpp:574
bool showSubstrate(bool theShow)
Definition: PartSet_PreviewSketchPlane.cpp:559
bool setAllUsingSketch(std::shared_ptr< ModelAPI_CompositeFeature > theSketch)
Updates CS (coordinate system), dimensions and accessories' configuration. Updates visibility of acce...
Definition: PartSet_PreviewSketchPlane.cpp:205
void resetCircularGrid()
Sets default steps and zero offsets.
Definition: PartSet_PreviewSketchPlane.cpp:663
PartSet_PreviewSketchPlane(PartSet_SketcherMgr *theManager)
Definition: PartSet_PreviewSketchPlane.cpp:131
bool showAxes(bool theShow)
Definition: PartSet_PreviewSketchPlane.cpp:544
void hideAll()
Hides all accessories.
Definition: PartSet_PreviewSketchPlane.cpp:603
static double defaultSketchSize()
Definition: PartSet_PreviewSketchPlane.cpp:815
void setCSAndSize(const gp_Ax3 &theCS, double theSize)
Updates CS (coordinate system), dimensions and accessories' configuration.
Definition: PartSet_PreviewSketchPlane.cpp:183
std::pair< double, double > getDimensions() const
Substrate dimensions. Substrate dimension coincides with one of the sketch face, if the latter is non...
Definition: PartSet_PreviewSketchPlane.cpp:610
bool reconfigureGridUsingSketch(std::shared_ptr< ModelAPI_CompositeFeature > theSketch)
Call it, after any preference of grid is changed in theSketch data directly. Updates grid configurati...
Definition: PartSet_PreviewSketchPlane.cpp:400
void resetRectangularGrid()
Sets default steps and zero offsets.
Definition: PartSet_PreviewSketchPlane.cpp:623
A class for management of sketch operations At the time of the sketcher operation active,...
Definition: PartSet_SketcherMgr.h:107