File size: 8,239 Bytes
985c397 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 | // SPDX-License-Identifier: LGPL-2.0-or-later
/***************************************************************************
* Copyright (c) 2024 WandererFan <wandererfan@gmail.com> *
* *
* This file is part of the FreeCAD CAx development system. *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Library General Public *
* License as published by the Free Software Foundation; either *
* version 2 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Library General Public License for more details. *
* *
* You should have received a copy of the GNU Library General Public *
* License along with this library; see the file COPYING.LIB. If not, *
* write to the Free Software Foundation, Inc., 59 Temple Place, *
* Suite 330, Boston, MA 02111-1307, USA *
* *
***************************************************************************/
//! DrawBrokenView produces a view of the Source shapes after a portion of the shapes
//! has been removed.
#ifndef DRAWBROKENVIEW_H_
#define DRAWBROKENVIEW_H_
#include <Mod/TechDraw/TechDrawGlobal.h>
#include <TopoDS_Shape.hxx>
#include <Base/Vector3D.h>
#include "DrawViewPart.h"
namespace TechDraw
{
struct BreakListEntry {
App::DocumentObject* breakObj;
double lowLimit; // the value to use for shifting shapes (the low end of the break)
double highLimit; // the other end of the break (the high end)
double netRemoved; // the removed amount of the break, less the gap size
// TODO: can the gap size change during the lifetime of BreakListEntry? if
// so, we need to save the gap size @ creation time?
};
using BreakList = std::vector<BreakListEntry>;
struct PieceLimitEntry {
double lowLimit;
double highLimit;
};
using PieceLimitList = std::vector<PieceLimitEntry>;
// NOLINTBEGIN
class TechDrawExport DrawBrokenView: public TechDraw::DrawViewPart
{
PROPERTY_HEADER_WITH_OVERRIDE(TechDraw::DrawBrokenView); // NOLINT
// NOLINTEND
public:
enum class BreakType : int {
NONE,
ZIGZAG,
SIMPLE
};
static const char* BreakTypeEnums[]; // NOLINT
DrawBrokenView();
~DrawBrokenView() override = default;
App::PropertyLinkList Breaks; // NOLINT
App::PropertyLength Gap; // NOLINT
App::DocumentObjectExecReturn* execute() override;
short mustExecute() const override;
PyObject *getPyObject() override;
const char* getViewProviderName() const override
{
return "TechDrawGui::ViewProviderViewPart";
}
std::pair<Base::Vector3d, Base::Vector3d>
breakPointsFromObj(const App::DocumentObject& breakObj) const;
std::pair<Base::Vector3d, Base::Vector3d>
breakBoundsFromObj(const App::DocumentObject& breakObj) const;
Base::Vector3d directionFromObj(const App::DocumentObject& breakObj) const;
Base::Vector3d guiDirectionFromObj(const App::DocumentObject& breakObj) const;
static bool isBreakObject(const App::DocumentObject& breakObj);
static bool isBreakObjectSketch(const App::DocumentObject& breakObj);
static std::vector<App::DocumentObject*> removeBreakObjects(std::vector<App::DocumentObject*> breaks,
std::vector<App::DocumentObject*> shapes);
static std::vector<TopoDS_Edge> edgesFromCompound(const TopoDS_Shape& compound);
Base::Vector3d mapPoint3dToView(Base::Vector3d point3d) const;
Base::Vector3d mapPoint2dFromView(Base::Vector3d point2d) const;
Base::Vector3d getCompressedCentroid() const;
double breaklineLength(const App::DocumentObject& breakObj) const;
private:
TopoDS_Shape breakShape(const TopoDS_Shape& shapeToBreak) const;
TopoDS_Shape compressShape(const TopoDS_Shape& shapeToCompress) const;
TopoDS_Shape apply1Break(const App::DocumentObject& breakObj, const TopoDS_Shape& inShape) const;
TopoDS_Shape makeHalfSpace(const Base::Vector3d& point,
const Base::Vector3d& direction,
const Base::Vector3d& pointInSpace) const;
std::pair<Base::Vector3d, Base::Vector3d>
breakPointsFromSketch(const App::DocumentObject& breakObj) const;
std::pair<Base::Vector3d, Base::Vector3d>
breakPointsFromEdge(const App::DocumentObject& breakObj) const;
std::pair<Base::Vector3d, Base::Vector3d>
breakBoundsFromSketch(const App::DocumentObject& breakObj) const;
std::pair<Base::Vector3d, Base::Vector3d>
breakBoundsFromEdge(const App::DocumentObject& breakObj) const;
double removedLengthFromObj(const App::DocumentObject& breakObj) const;
double breaklineLengthFromSketch(const App::DocumentObject& breakObj) const;
double breaklineLengthFromEdge(const App::DocumentObject& breakObj) const;
bool isVertical(const TopoDS_Edge& edge, const bool projected = false) const;
bool isVertical(std::pair<Base::Vector3d, Base::Vector3d>, bool projected = false) const;
bool isHorizontal(const TopoDS_Edge& edge, const bool projected = false) const;
TopoDS_Shape compressHorizontal(const TopoDS_Shape& inShape) const;
TopoDS_Shape compressVertical(const TopoDS_Shape& inShape) const;
static PieceLimitList getPieceLimits(const std::vector<TopoDS_Shape>& pieces, Base::Vector3d direction);
double getExpandGaps(double pointCoord,
const BreakList& compressedBreakList,
Base::Vector3d moveDirection,
std::vector<size_t>& fullGaps,
int& partialGapIndex) const;
BreakList makeSortedBreakList(const std::vector<App::DocumentObject*>& breaks,
const Base::Vector3d& direction,
const bool descend = false) const;
BreakList makeSortedBreakListCompressed(const std::vector<App::DocumentObject*>& breaks,
const Base::Vector3d& moveDirection,
const bool descend = false) const;
static std::vector<TopoDS_Shape> getPieces(const TopoDS_Shape& brokenShape);
static std::vector<TopoDS_Shape> getPiecesByType(const TopoDS_Shape& shapeToSearch,
TopAbs_ShapeEnum desiredShapeType,
TopAbs_ShapeEnum avoidShapeType = TopAbs_SHAPE);
static BreakList sortBreaks(BreakList& inList, bool descend = false);
static bool breakLess(const BreakListEntry& entry0, const BreakListEntry& entry1);
double shiftAmountShrink(double pointCoord, Base::Vector3d direction, const BreakList& sortedBreaks) const;
void printBreakList(const std::string& text, const BreakList& inBreaks) const;
std::pair<Base::Vector3d, Base::Vector3d>
scalePair(std::pair<Base::Vector3d, Base::Vector3d> inPair) const;
Base::Vector3d makePerpendicular(Base::Vector3d inDir) const;
bool moveThisPiece(PieceLimitEntry piece, BreakListEntry breakItem, Base::Vector3d moveDirection) const;
bool isDirectionReversed(Base::Vector3d direction) const;
Base::Vector3d m_unbrokenCenter;
TopoDS_Shape m_compressedShape;
};
using DrawBrokenViewPython = App::FeaturePythonT<DrawBrokenView>;
}//namespace TechDraw
#endif
|