clang -cc1 -cc1 -triple x86_64-pc-linux-gnu -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name lc_action_modify_line_join.cpp -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 2 -fhalf-no-semantic-interposition -mframe-pointer=none -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fdebug-compilation-dir=/home/runner/work/LibreCAD/LibreCAD/librecad/src -fcoverage-compilation-dir=/home/runner/work/LibreCAD/LibreCAD/librecad/src -resource-dir /usr/lib/llvm-18/lib/clang/18 -D _REENTRANT -D DWGSUPPORT -D MUPARSER_STATIC -D QC_APPDIR="librecad" -D LC_VERSION=2.2.2_alpha1-670-g0ffb38d79 -D LC_PRERELEASE=true; -D QT_NO_DEBUG -D QT_SVG_LIB -D QT_PRINTSUPPORT_LIB -D QT_WIDGETS_LIB -D QT_GUI_LIB -D QT_NETWORK_LIB -D QT_CORE_LIB -I . -I /usr/include -I ../../libraries/lciconengine -I ../../libraries/libdxfrw/src -I ../../libraries/libdxfrw/src/intern -I ../../libraries/jwwlib/src -I ../../libraries/shapelib/src -I cmd -I lib/actions -I lib/actions/visual_snap -I lib/actions/options -I lib/creation -I lib/debug -I lib/engine -I lib/engine/document -I lib/engine/document/blocks -I lib/engine/document/container -I lib/engine/document/dimstyles -I lib/engine/document/entities -I lib/engine/document/entities/support -I lib/engine/document/fonts -I lib/engine/document/io -I lib/engine/document/layers -I lib/engine/document/patterns -I lib/engine/document/selection -I lib/engine/document/textstyles -I lib/engine/document/ucs -I lib/engine/document/variables -I lib/engine/document/views -I lib/engine/clipboard -I lib/engine/overlays -I lib/engine/overlays/angles_base -I lib/engine/overlays/highlight -I lib/engine/overlays/preview -I lib/engine/overlays/references -I lib/engine/overlays/crosshair -I lib/engine/overlays/info_cursor -I lib/engine/overlays/overlay_box -I lib/engine/overlays/ucs_mark -I lib/engine/undo -I lib/engine/utils -I lib/engine/settings -I lib/fileio -I lib/filters -I lib/generators -I lib/generators/makercamsvg -I lib/generators/layers -I lib/generators/image -I lib/gui -I lib/gui/grid -I lib/gui/render -I lib/gui/render/headless -I lib/gui/render/widget -I lib/information -I lib/math -I lib/modification -I lib/selection -I lib/selection/metaentity -I lib/selection/metaentity/entities -I lib/printing -I lib/properties -I actions -I actions/dock_widgets -I actions/dock_widgets/block -I actions/dock_widgets/entity_info -I actions/dock_widgets/layer -I actions/dock_widgets/library -I actions/dock_widgets/ucs_list -I actions/drawing -I actions/drawing/draw -I actions/drawing/draw/arc -I actions/drawing/draw/circle -I actions/drawing/draw/curve -I actions/drawing/draw/spline -I actions/drawing/draw/dimensions -I actions/drawing/draw/ellipse -I actions/drawing/draw/hatch -I actions/drawing/draw/image -I actions/drawing/draw/line -I actions/drawing/draw/point -I actions/drawing/draw/rect -I actions/drawing/draw/polygon -I actions/drawing/draw/misc -I actions/drawing/draw/line/shapes -I actions/drawing/draw/line/misc -I actions/drawing/draw/line/shapes/rect -I actions/drawing/draw/line/shapes/polygon -I actions/drawing/draw/polyline -I actions/drawing/draw/text -I actions/drawing/edit -I actions/drawing/info -I actions/drawing/pick -I actions/drawing/modify -I actions/drawing/pen -I actions/drawing/rel_zero -I actions/drawing/selection -I actions/drawing/snap -I actions/drawing/zoom -I actions/file -I actions/options -I actions/print_preview -I ui -I ui/action_options -I ui/action_options/circle -I ui/action_options/curve -I ui/action_options/spline -I ui/action_options/dimensions -I ui/action_options/edit -I ui/action_options/image -I ui/action_options/info -I ui/action_options/insert -I ui/action_options/line -I ui/action_options/rect -I ui/action_options/polygon -I ui/action_options/misc -I ui/action_options/modify -I ui/action_options/ellipse -I ui/action_options/other -I ui/action_options/polyline -I ui/action_options/point -I ui/action_options/print_preview -I ui/action_options/selection -I ui/action_options/snap -I ui/action_options/text -I ui/actions -I ui/components -I ui/components/relative_position_assistant -I ui/components/comboboxes -I ui/components/containers -I ui/components/creators -I ui/components/layouts -I ui/components/pen -I ui/components/status_bar -I ui/components/toolbars -I ui/components/utils -I ui/dialogs -I ui/dialogs/actions -I ui/dialogs/actions/modify -I ui/dialogs/actions/quick_selection -I ui/dialogs/modify -I ui/dialogs/entity -I ui/dialogs/creators -I ui/dialogs/file -I ui/dialogs/file/export -I ui/dialogs/file/export/layers -I ui/dialogs/file/export/image -I ui/dialogs/file/export/makercam -I ui/dialogs/main -I ui/dialogs/settings -I ui/dialogs/settings/dimstyles -I ui/dialogs/settings/dimstyles/dimstyle_manager -I ui/dialogs/settings/dimstyles/dimstyle_manager/support -I ui/dialogs/settings/options_device -I ui/dialogs/settings/options_drawing -I ui/dialogs/settings/options_general -I ui/dialogs/settings/options_widget -I ui/dialogs/settings/shortcuts -I ui/dock_widgets -I ui/dock_widgets/block_widget -I ui/dock_widgets/command_line -I ui/dock_widgets/entity_info -I ui/dock_widgets/layer_widget -I ui/dock_widgets/layers_tree -I ui/dock_widgets/library_widget -I ui/dock_widgets/pen_palette -I ui/dock_widgets/pen_wizard -I ui/dock_widgets/property_sheet -I ui/dock_widgets/property_sheet/lib -I ui/dock_widgets/property_sheet/lib/properties -I ui/dock_widgets/property_sheet/lib/view -I ui/dock_widgets/property_sheet/lib/view/edit -I ui/dock_widgets/property_sheet/lib/widgets -I ui/dock_widgets/property_sheet/lib/widgets/sheet -I ui/dock_widgets/property_sheet/metaentity -I ui/dock_widgets/property_sheet/metaentity/entities -I ui/dock_widgets/property_sheet/metaentity/entities/document -I ui/dock_widgets/property_sheet/properties -I ui/dock_widgets/property_sheet/properties/action -I ui/dock_widgets/property_sheet/properties/bool -I ui/dock_widgets/property_sheet/properties/color -I ui/dock_widgets/property_sheet/properties/double -I ui/dock_widgets/property_sheet/properties/enum -I ui/dock_widgets/property_sheet/properties/int -I ui/dock_widgets/property_sheet/properties/layer -I ui/dock_widgets/property_sheet/properties/linetype -I ui/dock_widgets/property_sheet/properties/linewidth -I ui/dock_widgets/property_sheet/properties/rect -I ui/dock_widgets/property_sheet/properties/rsvector -I ui/dock_widgets/property_sheet/properties/string -I ui/dock_widgets/views_list -I ui/dock_widgets/ucs_list -I ui/dock_widgets/workspaces -I ui/dock_widgets/cad -I ui/main -I ui/main/init -I ui/main/persistence -I ui/main/release_check -I ui/main/support -I ui/main/fontviewer -I ui/main/workspaces -I ui/view -I main -I main/console_dxf2pdf -I test -I plugins -I ../res -I ../res/arrows -I ../res/controls -I ../res/dxf -I ../res/gdt -I ../res/icons -I ../res/images -I ../../../Qt/6.9.0/gcc_64/include -I ../../../Qt/6.9.0/gcc_64/include/QtSvg -I ../../../Qt/6.9.0/gcc_64/include/QtPrintSupport -I ../../../Qt/6.9.0/gcc_64/include/QtWidgets -I ../../../Qt/6.9.0/gcc_64/include/QtGui -I ../../../Qt/6.9.0/gcc_64/include/QtNetwork -I ../../../Qt/6.9.0/gcc_64/include/QtCore -I ../../generated/librecad/moc -I ../../generated/librecad/ui -I ../../../Qt/6.9.0/gcc_64/mkspecs/linux-g++ -internal-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/14/../../../../include/c++/14 -internal-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/14/../../../../include/x86_64-linux-gnu/c++/14 -internal-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/14/../../../../include/c++/14/backward -internal-isystem /usr/lib/llvm-18/lib/clang/18/include -internal-isystem /usr/local/include -internal-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/14/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -O2 -std=gnu++1z -fdeprecated-macro -ferror-limit 19 -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -fcxx-exceptions -fexceptions -vectorize-loops -vectorize-slp -analyzer-output=html -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /home/runner/work/LibreCAD/LibreCAD/out/2026-09-15-234850-5000-1 -x c++ actions/drawing/modify/lc_action_modify_line_join.cpp
| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | |
| 14 | |
| 15 | |
| 16 | |
| 17 | |
| 18 | |
| 19 | |
| 20 | |
| 21 | |
| 22 | |
| 23 | #include "lc_action_modify_line_join.h" |
| 24 | |
| 25 | #include "lc_actioninfomessagebuilder.h" |
| 26 | #include "lc_line_join_options_filler.h" |
| 27 | #include "lc_line_join_options_widget.h" |
| 28 | #include "lc_linemath.h" |
| 29 | #include "rs_document.h" |
| 30 | #include "rs_information.h" |
| 31 | #include "rs_line.h" |
| 32 | #include "rs_pen.h" |
| 33 | #include "rs_polyline.h" |
| 34 | |
| 35 | LC_ActionModifyLineJoin::LC_ActionModifyLineJoin(LC_ActionContext *actionContext): |
| 36 | LC_AbstractActionWithPreview("ActionModifyLineJoin", actionContext, RS2::ActionModifyLineJoin){ |
| 37 | } |
| 38 | |
| 39 | LC_ActionModifyLineJoin::~LC_ActionModifyLineJoin() = default; |
| 40 | |
| 41 | void LC_ActionModifyLineJoin::doSaveOptions() { |
| 42 | save("Polyline", m_createPolyline); |
| 43 | save("RemoveOriginals", m_removeOriginalLines); |
| 44 | save("AttributesSource", m_attributesSource); |
| 45 | save("Line1EdgeMode", m_line1EdgeMode); |
| 46 | save("Line2EdgeMode", m_line2EdgeMode); |
| 47 | } |
| 48 | |
| 49 | void LC_ActionModifyLineJoin::doLoadOptions() { |
| 50 | m_createPolyline = loadBool("Polyline", false); |
| 51 | m_removeOriginalLines = loadBool("RemoveOriginals", true); |
| 52 | m_attributesSource = loadInt("AttributesSource", ATTRIBUTES_ACTIVE_PEN_LAYER); |
| 53 | m_line1EdgeMode = loadInt("Line1EdgeMode", EDGE_EXTEND_TRIM); |
| 54 | m_line2EdgeMode = loadInt("Line2EdgeMode", EDGE_EXTEND_TRIM); |
| 55 | } |
| 56 | |
| 57 | void LC_ActionModifyLineJoin::init(const int status){ |
| 58 | m_line1 = nullptr; |
| 59 | m_line2 = nullptr; |
| 60 | LC_AbstractActionWithPreview::init(status); |
| 61 | } |
| 62 | |
| 63 | void LC_ActionModifyLineJoin::doInitWithContextEntity(RS_Entity* contextEntity, const RS_Vector& clickPos) { |
| 64 | if (isLine(contextEntity)) { |
| 65 | m_line1 = static_cast<RS_Line*>(contextEntity); |
| 66 | m_line1ClickPosition = contextEntity->getNearestPointOnEntity(clickPos, true); |
| 67 | setStatus(SetLine2); |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | |
| 72 | |
| 73 | |
| 74 | RS_Line *LC_ActionModifyLineJoin::catchLine(const LC_MouseEvent *e, const bool forPreview) const { |
| 75 | RS_Entity *en = forPreview ? catchModifiableAndDescribe(e, m_lineType) :catchModifiableEntity(e, m_lineType); |
| 76 | RS_Line *snappedLine = nullptr; |
| 77 | |
| 78 | if (isLine(en) && RS_Information::isEditable(en)){ |
| 79 | snappedLine = dynamic_cast<RS_Line *>(en); |
| 80 | } |
| 81 | return snappedLine; |
| 82 | } |
| 83 | |
| 84 | void LC_ActionModifyLineJoin::drawSnapper() { |
| 85 | |
| 86 | } |
| 87 | |
| 88 | void LC_ActionModifyLineJoin::doPreparePreviewEntities(const LC_MouseEvent* e, [[maybe_unused]]RS_Vector &snap, QList<RS_Entity *> &list, const int status){ |
| 89 | const RS_Line *snappedLine = catchLine(e, true); |
| 90 | switch (status) { |
| 91 | case SetLine1: { |
| 92 | if (snappedLine != nullptr){ |
| 93 | highlightHover(snappedLine); |
| 94 | } |
| 95 | break; |
| 96 | } |
| 97 | case SetLine2: { |
| 98 | if (snappedLine == m_line1){ |
| 99 | snappedLine = nullptr; |
| 100 | } |
| 101 | highlightSelected(m_line1); |
| 102 | if (snappedLine != nullptr){ |
| 103 | highlightHover(snappedLine); |
| 104 | |
| 105 | const RS_Vector coord = e->graphPoint; |
| 106 | const LC_LineJoinData *lineJoinData = createLineJoinData(snappedLine, coord); |
| 107 | if (lineJoinData != nullptr){ |
| 108 | RS_Polyline *polyline = lineJoinData->polyline; |
| 109 | if (polyline != nullptr){ |
| 110 | list << polyline; |
| 111 | } |
| 112 | |
| 113 | if (m_showRefEntitiesOnPreview) { |
| 114 | if (!lineJoinData->parallelLines) { |
| 115 | const RS_Vector &intersectionPoint = lineJoinData->intersectPoint; |
| 116 | createRefPoint(intersectionPoint, list); |
| 117 | } |
| 118 | |
| 119 | const RS_Vector &major1 = lineJoinData->majorPointLine1; |
| 120 | if (major1.valid) { |
| 121 | createRefPoint(major1, list); |
| 122 | } |
| 123 | |
| 124 | const RS_Vector &major2 = lineJoinData->majorPointLine2; |
| 125 | if (major2.valid) { |
| 126 | createRefPoint(major2, list); |
| 127 | } |
| 128 | } |
| 129 | |
| 130 | if (isInfoCursorForModificationEnabled()){ |
| 131 | auto builder = msgStart() |
| 132 | .string(tr("Lines Join")); |
| 133 | if (lineJoinData->parallelLines) { |
| 134 | builder.add(tr("Lines are parallel")); |
| 135 | } |
| 136 | else{ |
| 137 | builder.vector(tr("Intersection:"), lineJoinData->intersectPoint); |
| 138 | } |
| 139 | builder.toInfoCursorZone2(false); |
| 140 | } |
| 141 | |
| 142 | |
| 143 | delete lineJoinData; |
| 144 | } |
| 145 | } |
| 146 | break; |
| 147 | } |
| 148 | case ResolveFirstLineTrim: { |
| 149 | if (snappedLine != m_line1){ |
| 150 | |
| 151 | |
| 152 | snappedLine = nullptr; |
| 153 | } |
| 154 | highlightSelected(m_line1); |
| 155 | if (snappedLine != nullptr){ |
| 156 | |
| 157 | |
| 158 | const RS_Vector coord = e->graphPoint; |
| 159 | updateLine1TrimData(coord); |
| 160 | |
| 161 | const RS_Polyline *polyline = m_linesJoinData->polyline; |
| 162 | if (polyline != nullptr){ |
| 163 | list << polyline->clone(); |
| 164 | if (m_showRefEntitiesOnPreview) { |
| 165 | if (!m_linesJoinData->parallelLines) { |
| 166 | const RS_Vector &intersectionPoint = m_linesJoinData->intersectPoint; |
| 167 | createRefPoint(intersectionPoint, list); |
| 168 | } |
| 169 | createRefPoint(m_linesJoinData->majorPointLine1, list); |
| 170 | createRefPoint(m_linesJoinData->majorPointLine2, list); |
| 171 | } |
| 172 | } |
| 173 | } |
| 174 | break; |
| 175 | } |
| 176 | default: |
| 177 | break; |
| 178 | } |
| 179 | } |
| 180 | |
| 181 | void LC_ActionModifyLineJoin::doOnLeftMouseButtonRelease(const LC_MouseEvent* e, const int status, [[maybe_unused]]const RS_Vector &snapPoint){ |
| 182 | RS_Line *snappedLine = catchLine(e, false); |
| 183 | switch (status) { |
| 1 | Control jumps to 'case ResolveFirstLineTrim:' at line 247 | |
|
| 184 | case SetLine1: { |
| 185 | if (snappedLine != nullptr){ |
| 186 | m_line1 = snappedLine; |
| 187 | m_line1ClickPosition = snapPoint; |
| 188 | setStatus(SetLine2); |
| 189 | } else { |
| 190 | commandMessage(tr("No line selected")); |
| 191 | } |
| 192 | break; |
| 193 | } |
| 194 | case SetLine2: { |
| 195 | if (snappedLine == m_line1){ |
| 196 | snappedLine = nullptr; |
| 197 | } |
| 198 | if (snappedLine != nullptr){ |
| 199 | m_line2 = snappedLine; |
| 200 | const RS_Vector snap = e->graphPoint; |
| 201 | LC_LineJoinData *joinData = createLineJoinData(snappedLine, snap); |
| 202 | if (joinData != nullptr){ |
| 203 | |
| 204 | if (joinData->parallelLines){ |
| 205 | |
| 206 | if (joinData->straightLinesConnection){ |
| 207 | |
| 208 | m_linesJoinData = joinData; |
| 209 | trigger(); |
| 210 | } else { |
| 211 | delete joinData; |
| 212 | commandMessage(tr("Lines are parallel, can't merge")); |
| 213 | } |
| 214 | } else { |
| 215 | if (joinData->areLinesAlreadyIntersected()){ |
| 216 | |
| 217 | commandMessage(tr("Lines already intersects, can't merge")); |
| 218 | delete joinData; |
| 219 | } else { |
| 220 | |
| 221 | |
| 222 | |
| 223 | |
| 224 | |
| 225 | bool firstLineTrimShouldBeSpecified = joinData->isIntersectionOnLine1(); |
| 226 | if (m_line1EdgeMode != EDGE_EXTEND_TRIM){ |
| 227 | firstLineTrimShouldBeSpecified = false; |
| 228 | } |
| 229 | m_linesJoinData = joinData; |
| 230 | if (firstLineTrimShouldBeSpecified){ |
| 231 | |
| 232 | setStatus(ResolveFirstLineTrim); |
| 233 | highlightEntity(m_line1); |
| 234 | redraw(); |
| 235 | } else { |
| 236 | |
| 237 | trigger(); |
| 238 | } |
| 239 | } |
| 240 | } |
| 241 | } else { |
| 242 | commandMessage(tr("No line selected")); |
| 243 | } |
| 244 | } |
| 245 | break; |
| 246 | } |
| 247 | case ResolveFirstLineTrim: { |
| 248 | if (snappedLine == m_line1){ |
| 2 | | Assuming 'snappedLine' is equal to field 'm_line1' | |
|
| |
| 249 | const RS_Vector snap = e->graphPoint; |
| 250 | |
| 251 | updateLine1TrimData(snap); |
| 4 | | Calling 'LC_ActionModifyLineJoin::updateLine1TrimData' | |
|
| 252 | |
| 253 | const RS_Polyline *polyline = m_linesJoinData->polyline; |
| 254 | if (polyline != nullptr){ |
| 255 | trigger(); |
| 256 | } |
| 257 | } else { |
| 258 | highlightEntity(m_line1); |
| 259 | } |
| 260 | break; |
| 261 | } |
| 262 | default: |
| 263 | break; |
| 264 | } |
| 265 | } |
| 266 | |
| 267 | void LC_ActionModifyLineJoin::doBack(const LC_MouseEvent* e, const int status){ |
| 268 | LC_AbstractActionWithPreview::doBack(e, status); |
| 269 | switch (status) { |
| 270 | case SetLine1: |
| 271 | init(SetLine1 - 1); |
| 272 | break; |
| 273 | case SetLine2: { |
| 274 | setStatus(SetLine1); |
| 275 | break; |
| 276 | } |
| 277 | case ResolveFirstLineTrim: { |
| 278 | setStatus(SetLine2); |
| 279 | break; |
| 280 | } |
| 281 | default: |
| 282 | initPrevious(status); |
| 283 | break; |
| 284 | } |
| 285 | } |
| 286 | |
| 287 | void LC_ActionModifyLineJoin::doAfterTrigger(){ |
| 288 | LC_AbstractActionWithPreview::doAfterTrigger(); |
| 289 | delete m_linesJoinData; |
| 290 | m_linesJoinData = nullptr; |
| 291 | redraw(); |
| 292 | |
| 293 | init(SetLine1); |
| 294 | } |
| 295 | |
| 296 | bool LC_ActionModifyLineJoin::doCheckMayTrigger(){ |
| 297 | return m_linesJoinData != nullptr; |
| 298 | } |
| 299 | |
| 300 | bool LC_ActionModifyLineJoin::isSetActivePenAndLayerOnTrigger(){ |
| 301 | |
| 302 | return false; |
| 303 | } |
| 304 | |
| 305 | bool LC_ActionModifyLineJoin::doTriggerEntitiesPrepare(LC_DocumentModificationBatch& ctx){ |
| 306 | if (m_linesJoinData->parallelLines && m_linesJoinData->straightLinesConnection){ |
| 307 | |
| 308 | auto *line = createLine(m_linesJoinData->majorPointLine1, m_linesJoinData->majorPointLine2, ctx.entitiesToAdd); |
| 309 | |
| 310 | applyAttributes(line, true); |
| 311 | } else { |
| 312 | |
| 313 | const RS_Vector &intersectionPoint = m_linesJoinData->intersectPoint; |
| 314 | |
| 315 | |
| 316 | |
| 317 | const RS_Vector &major1 = m_linesJoinData->majorPointLine1; |
| 318 | const RS_Vector &major2 = m_linesJoinData->majorPointLine2; |
| 319 | |
| 320 | if (m_createPolyline && major1.valid && major2.valid){ |
| 321 | auto *poly = new RS_Polyline(m_document); |
| 322 | poly->addVertex(major1); |
| 323 | poly->addVertex(intersectionPoint); |
| 324 | poly->addVertex(major2); |
| 325 | applyAttributes(poly, true); |
| 326 | ctx += poly; |
| 327 | |
| 328 | } else { |
| 329 | if (major1.valid){ |
| 330 | |
| 331 | RS_Line* l1 = createLine(major1, intersectionPoint, ctx.entitiesToAdd); |
| 332 | applyAttributes(l1, true); |
| 333 | } |
| 334 | if (major2.valid){ |
| 335 | |
| 336 | RS_Line* l2 = createLine(intersectionPoint, major2, ctx.entitiesToAdd); |
| 337 | applyAttributes(l2, false); |
| 338 | } |
| 339 | } |
| 340 | } |
| 341 | |
| 342 | if (m_removeOriginalLines){ |
| 343 | |
| 344 | if (m_line1EdgeMode == EDGE_EXTEND_TRIM){ |
| 345 | ctx -= m_line1; |
| 346 | } |
| 347 | |
| 348 | if (m_line2EdgeMode == EDGE_EXTEND_TRIM){ |
| 349 | ctx -= m_line2; |
| 350 | } |
| 351 | } |
| 352 | return true; |
| 353 | } |
| 354 | |
| 355 | |
| 356 | |
| 357 | |
| 358 | |
| 359 | |
| 360 | void LC_ActionModifyLineJoin::applyAttributes(RS_Entity *e, bool forLine1){ |
| 361 | RS_Pen pen; |
| 362 | RS_Layer *layer = nullptr; |
| 363 | switch (m_attributesSource) { |
| 364 | case ATTRIBUTES_LINE_1: { |
| 365 | pen = m_line1->getPen(false); |
| 366 | e->setPen(pen); |
| 367 | layer = m_line1->getLayer(true); |
| 368 | e->setLayer(layer); |
| 369 | break; |
| 370 | } |
| 371 | case ATTRIBUTES_BOTH_LINES: { |
| 372 | |
| 373 | if (forLine1){ |
| 374 | pen = m_line1->getPen(false); |
| 375 | e->setPen(pen); |
| 376 | layer = m_line1->getLayer(true); |
| 377 | e->setLayer(layer); |
| 378 | } else { |
| 379 | pen = m_line2->getPen(false); |
| 380 | e->setPen(pen); |
| 381 | layer = m_line2->getLayer(true); |
| 382 | e->setLayer(layer); |
| 383 | } |
| 384 | break; |
| 385 | } |
| 386 | case ATTRIBUTES_LINE_2: { |
| 387 | |
| 388 | pen = m_line2->getPen(false); |
| 389 | e->setPen(pen); |
| 390 | layer = m_line2->getLayer(true); |
| 391 | e->setLayer(layer); |
| 392 | break; |
| 393 | } |
| 394 | case ATTRIBUTES_ACTIVE_PEN_LAYER: { |
| 395 | |
| 396 | setPenAndLayerToActive(e); |
| 397 | break; |
| 398 | } |
| 399 | default: |
| 400 | break; |
| 401 | } |
| 402 | } |
| 403 | |
| 404 | |
| 405 | |
| 406 | |
| 407 | |
| 408 | |
| 409 | |
| 410 | LC_ActionModifyLineJoin::LC_LineJoinData *LC_ActionModifyLineJoin::createLineJoinData(const RS_Line *secondLine, const RS_Vector &snapPoint) const { |
| 411 | LC_LineJoinData *result = nullptr; |
| 412 | |
| 413 | if (m_line1 != nullptr && secondLine != nullptr){ |
| 414 | |
| 415 | |
| 416 | const RS_Vector line1Start = m_line1->getStartpoint(); |
| 417 | const RS_Vector line1End = m_line1->getEndpoint(); |
| 418 | const RS_Vector line2Start = secondLine->getStartpoint(); |
| 419 | const RS_Vector line2End = secondLine->getEndpoint(); |
| 420 | |
| 421 | const RS_Vector intersection = LC_LineMath::getIntersectionLineLine(line1Start, line1End, line2Start, line2End); |
| 422 | |
| 423 | |
| 424 | if (intersection.valid){ |
| 425 | result = proceedNonParallelLines(m_line1ClickPosition, snapPoint, intersection, line1Start, line1End, line2Start, line2End); |
| 426 | |
| 427 | } else { |
| 428 | result = proceedParallelLinesJoin(line1Start, line1End, line2Start, line2End); |
| 429 | } |
| 430 | } |
| 431 | return result; |
| 432 | } |
| 433 | |
| 434 | |
| 435 | |
| 436 | |
| 437 | |
| 438 | |
| 439 | |
| 440 | |
| 441 | |
| 442 | |
| 443 | |
| 444 | |
| 445 | LC_ActionModifyLineJoin::LC_LineJoinData *LC_ActionModifyLineJoin::proceedNonParallelLines(const RS_Vector& line1ClickPoint, const RS_Vector &snapPoint, |
| 446 | const RS_Vector &intersectPoint, |
| 447 | const RS_Vector &line1Start, const RS_Vector &line1End, |
| 448 | const RS_Vector &line2Start, const RS_Vector &line2End) const { |
| 449 | auto *result = new LC_LineJoinData(); |
| 450 | |
| 451 | result->intersectPoint = intersectPoint; |
| 452 | result->parallelLines = false; |
| 453 | |
| 454 | |
| 455 | auto *polyline = new RS_Polyline(m_document); |
| 456 | |
| 457 | |
| 458 | |
| 459 | const LC_PointsDisposition line1Disposition = determine3PointsDisposition(line1Start, line1End, intersectPoint, line1ClickPoint); |
| 460 | |
| 461 | |
| 462 | |
| 463 | |
| 464 | const RS_Vector pointFromLine1 = getMajorPointFromLine(m_line1EdgeMode, line1Start, line1End, line1Disposition); |
| 465 | result->majorPointLine1 = pointFromLine1; |
| 466 | |
| 467 | |
| 468 | if (pointFromLine1.valid){ |
| 469 | polyline->addVertex(pointFromLine1); |
| 470 | } |
| 471 | |
| 472 | |
| 473 | polyline->addVertex(intersectPoint); |
| 474 | |
| 475 | |
| 476 | |
| 477 | const LC_PointsDisposition line2Disposition = determine3PointsDisposition(line2Start, line2End, intersectPoint, snapPoint); |
| 478 | |
| 479 | |
| 480 | const RS_Vector pointFromLine2 = getMajorPointFromLine(m_line2EdgeMode, line2Start, line2End, line2Disposition); |
| 481 | result->majorPointLine2 = pointFromLine2; |
| 482 | |
| 483 | |
| 484 | if (pointFromLine2.valid){ |
| 485 | polyline->addVertex(pointFromLine2); |
| 486 | } |
| 487 | |
| 488 | |
| 489 | result->polyline = polyline; |
| 490 | result->line1Disposition = line1Disposition; |
| 491 | result->line2Disposition = line2Disposition; |
| 492 | result->intersectPoint = intersectPoint; |
| 493 | return result; |
| 494 | } |
| 495 | |
| 496 | |
| 497 | |
| 498 | |
| 499 | |
| 500 | |
| 501 | void LC_ActionModifyLineJoin::updateLine1TrimData(const RS_Vector& snap) const { |
| 502 | |
| 503 | const RS_Vector &line1Start = m_line1->getStartpoint(); |
| 5 | | Called C++ object pointer is null |
|
| 504 | const RS_Vector &line1End = m_line1->getEndpoint(); |
| 505 | RS_Polyline *polyline = m_linesJoinData->polyline; |
| 506 | |
| 507 | delete polyline; |
| 508 | |
| 509 | polyline = new RS_Polyline(m_document); |
| 510 | m_linesJoinData->polyline = polyline; |
| 511 | |
| 512 | const RS_Vector &intersection = m_linesJoinData->intersectPoint; |
| 513 | |
| 514 | |
| 515 | const LC_PointsDisposition line1Disposition = determine3PointsDisposition(line1Start, line1End, intersection, snap); |
| 516 | |
| 517 | |
| 518 | const RS_Vector pointFromLine1 = getMajorPointFromLine(m_line1EdgeMode, line1Start, line1End, line1Disposition); |
| 519 | m_linesJoinData->majorPointLine1 = pointFromLine1; |
| 520 | |
| 521 | |
| 522 | if (line1Start.valid){ |
| 523 | polyline->addVertex(pointFromLine1); |
| 524 | } |
| 525 | |
| 526 | |
| 527 | polyline->addVertex(intersection); |
| 528 | |
| 529 | |
| 530 | const RS_Vector pointFromLine2 = getMajorPointFromLine(m_line2EdgeMode, m_line2->getStartpoint(), m_line2->getEndpoint(), m_linesJoinData->line2Disposition); |
| 531 | m_linesJoinData->majorPointLine2 = pointFromLine2; |
| 532 | |
| 533 | |
| 534 | if (pointFromLine2.valid){ |
| 535 | polyline->addVertex(pointFromLine2); |
| 536 | } |
| 537 | } |
| 538 | |
| 539 | |
| 540 | |
| 541 | |
| 542 | |
| 543 | |
| 544 | |
| 545 | |
| 546 | |
| 547 | |
| 548 | RS_Vector LC_ActionModifyLineJoin::getMajorPointFromLine( |
| 549 | const int edgeMode, |
| 550 | const RS_Vector &lineStart, |
| 551 | const RS_Vector &lineEnd, |
| 552 | const LC_PointsDisposition &lineDisposition) const{ |
| 553 | auto result = RS_Vector(false); |
| 554 | switch (edgeMode) { |
| 555 | case EDGE_EXTEND_TRIM: |
| 556 | switch (lineDisposition.dispositionMode) { |
| 557 | case LC_PointsDisposition::BOTH_POINTS_ON_RIGHT: |
| 558 | case LC_PointsDisposition::BOTH_POINTS_ON_LEFT: { |
| 559 | result = lineDisposition.farPoint; |
| 560 | break; |
| 561 | } |
| 562 | case LC_PointsDisposition::MIDDLE_END_LEFT: { |
| 563 | if (lineDisposition.snapSelectionOnLeft){ |
| 564 | result = lineEnd; |
| 565 | } else { |
| 566 | result = lineStart; |
| 567 | } |
| 568 | break; |
| 569 | } |
| 570 | case LC_PointsDisposition::MIDDLE_START_LEFT: { |
| 571 | if (lineDisposition.snapSelectionOnLeft){ |
| 572 | result = lineStart; |
| 573 | } else { |
| 574 | result = lineEnd; |
| 575 | } |
| 576 | break; |
| 577 | } |
| 578 | default: |
| 579 | break; |
| 580 | } |
| 581 | break; |
| 582 | case EDGE_ADD_SEGMENT: |
| 583 | switch (lineDisposition.dispositionMode) { |
| 584 | case LC_PointsDisposition::BOTH_POINTS_ON_RIGHT: |
| 585 | case LC_PointsDisposition::BOTH_POINTS_ON_LEFT: { |
| 586 | |
| 587 | |
| 588 | result = lineDisposition.closestPoint; |
| 589 | break; |
| 590 | } |
| 591 | case LC_PointsDisposition::MIDDLE_END_LEFT: |
| 592 | case LC_PointsDisposition::MIDDLE_START_LEFT: { |
| 593 | |
| 594 | |
| 595 | break; |
| 596 | } |
| 597 | default: |
| 598 | break; |
| 599 | } |
| 600 | break; |
| 601 | case EDGE_NO_MODIFICATION: |
| 602 | break; |
| 603 | default: |
| 604 | break; |
| 605 | } |
| 606 | return result; |
| 607 | } |
| 608 | |
| 609 | |
| 610 | |
| 611 | |
| 612 | |
| 613 | |
| 614 | |
| 615 | |
| 616 | |
| 617 | LC_ActionModifyLineJoin::LC_LineJoinData *LC_ActionModifyLineJoin::proceedParallelLinesJoin( |
| 618 | const RS_Vector &line1Start, const RS_Vector &line1End, |
| 619 | const RS_Vector &line2Start, const RS_Vector &line2End) const{ |
| 620 | |
| 621 | auto result = new LC_LineJoinData(); |
| 622 | result->parallelLines = true; |
| 623 | |
| 624 | |
| 625 | bool sameRay = LC_LineMath::areLinesOnSameRay(line1Start, line1End, line2Start, line2End); |
| 626 | |
| 627 | if (sameRay){ |
| 628 | result->straightLinesConnection = true; |
| 629 | |
| 630 | |
| 631 | |
| 632 | double angle = line1Start.angleTo(line1End); |
| 633 | |
| 634 | |
| 635 | auto startOnX1 = RS_Vector(line1Start); |
| 636 | auto endOnX1 = RS_Vector(line1End); |
| 637 | auto startOnX2 = RS_Vector(line2Start); |
| 638 | auto endOnX2 = RS_Vector(line2End); |
| 639 | |
| 640 | |
| 641 | endOnX1.rotate(startOnX1, -angle); |
| 642 | startOnX2.rotate(startOnX1, -angle); |
| 643 | endOnX2.rotate(startOnX1, -angle); |
| 644 | |
| 645 | |
| 646 | double sx1 = startOnX1.x; |
| 647 | double ex1 = endOnX1.x; |
| 648 | double sx2 = startOnX2.x; |
| 649 | double ex2 = endOnX2.x; |
| 650 | |
| 651 | |
| 652 | |
| 653 | RS_Vector s1 = line1Start; |
| 654 | RS_Vector e1 = line1End; |
| 655 | RS_Vector s2 = line2Start; |
| 656 | RS_Vector e2 = line2End; |
| 657 | |
| 658 | |
| 659 | |
| 660 | |
| 661 | |
| 662 | |
| 663 | |
| 664 | if (ex1 < sx1){ |
| 665 | std::swap(sx1, ex1); |
| 666 | std::swap(s1, e1); |
| 667 | } |
| 668 | |
| 669 | if (ex2 < sx2){ |
| 670 | std::swap(sx2, ex2); |
| 671 | std::swap(s2, e2); |
| 672 | } |
| 673 | |
| 674 | RS_Vector leftPoint; |
| 675 | RS_Vector rightPoint; |
| 676 | RS_Vector middleLeftPoint; |
| 677 | RS_Vector middleRightPoint; |
| 678 | |
| 679 | |
| 680 | bool hasIntersection = false; |
| 681 | |
| 682 | if (sx1 < sx2){ |
| 683 | hasIntersection = sx2 < ex1; |
| 684 | leftPoint = s1; |
| 685 | if (hasIntersection){ |
| 686 | if (ex1 > ex2){ |
| 687 | rightPoint = e1; |
| 688 | } else { |
| 689 | rightPoint = e2; |
| 690 | } |
| 691 | } else { |
| 692 | rightPoint = e2; |
| 693 | middleLeftPoint = e1; |
| 694 | middleRightPoint = s2; |
| 695 | } |
| 696 | } else { |
| 697 | hasIntersection = sx1 < ex2; |
| 698 | leftPoint = s2; |
| 699 | if (hasIntersection){ |
| 700 | if (ex1 > ex2){ |
| 701 | rightPoint = e1; |
| 702 | } else { |
| 703 | rightPoint = e2; |
| 704 | } |
| 705 | } else { |
| 706 | rightPoint = e1; |
| 707 | middleRightPoint = s1; |
| 708 | middleLeftPoint = e2; |
| 709 | } |
| 710 | } |
| 711 | |
| 712 | |
| 713 | |
| 714 | |
| 715 | if (m_line1EdgeMode == EDGE_EXTEND_TRIM || m_line2EdgeMode == EDGE_EXTEND_TRIM){ |
| 716 | auto *polyline = new RS_Polyline(m_document); |
| 717 | |
| 718 | |
| 719 | polyline->addVertex(leftPoint); |
| 720 | polyline->addVertex(rightPoint); |
| 721 | |
| 722 | |
| 723 | |
| 724 | |
| 725 | |
| 726 | |
| 727 | result->majorPointLine1 = leftPoint; |
| 728 | result->majorPointLine2 = rightPoint; |
| 729 | |
| 730 | result->polyline = polyline; |
| 731 | } else if (m_line1EdgeMode == EDGE_ADD_SEGMENT && m_line2EdgeMode == EDGE_ADD_SEGMENT){ |
| 732 | |
| 733 | |
| 734 | if (!hasIntersection){ |
| 735 | |
| 736 | auto *polyline = new RS_Polyline(m_document); |
| 737 | |
| 738 | |
| 739 | polyline->addVertex(middleLeftPoint); |
| 740 | polyline->addVertex(middleRightPoint); |
| 741 | |
| 742 | |
| 743 | result->majorPointLine1 = middleLeftPoint; |
| 744 | result->majorPointLine2 = middleRightPoint; |
| 745 | result->polyline = polyline; |
| 746 | } |
| 747 | } |
| 748 | } else { |
| 749 | result->straightLinesConnection = false; |
| 750 | } |
| 751 | return result; |
| 752 | } |
| 753 | |
| 754 | |
| 755 | |
| 756 | |
| 757 | |
| 758 | |
| 759 | |
| 760 | |
| 761 | |
| 762 | |
| 763 | LC_ActionModifyLineJoin::LC_PointsDisposition LC_ActionModifyLineJoin::determine3PointsDisposition( |
| 764 | const RS_Vector& start, |
| 765 | const RS_Vector& end, |
| 766 | const RS_Vector& intersection, |
| 767 | const RS_Vector &snapPoint) const{ |
| 768 | |
| 769 | |
| 770 | |
| 771 | |
| 772 | const double angle = start.angleTo(end); |
| 773 | |
| 774 | |
| 775 | auto startOnX = RS_Vector(start); |
| 776 | auto endOnX = RS_Vector(end); |
| 777 | |
| 778 | startOnX.rotate(intersection, -angle); |
| 779 | endOnX.rotate(intersection, -angle); |
| 780 | |
| 781 | |
| 782 | RS_Vector snapProjection = LC_LineMath::getNearestPointOnInfiniteLine(snapPoint, start, end); |
| 783 | |
| 784 | |
| 785 | const RS_Vector snapOnX = snapProjection.rotate(intersection, -angle); |
| 786 | |
| 787 | |
| 788 | |
| 789 | const double ix = intersection.x; |
| 790 | const double delta = ix; |
| 791 | |
| 792 | |
| 793 | double startX = startOnX.x; |
| 794 | double endX = endOnX.x; |
| 795 | double snapX = snapOnX.x; |
| 796 | |
| 797 | startX -= delta; |
| 798 | endX -= delta; |
| 799 | snapX -= delta; |
| 800 | |
| 801 | LC_PointsDisposition result; |
| 802 | |
| 803 | |
| 804 | if (startX > 0){ |
| 805 | if (endX > 0){ |
| 806 | result.dispositionMode = LC_PointsDisposition::BOTH_POINTS_ON_RIGHT; |
| 807 | } else { |
| 808 | result.dispositionMode = LC_PointsDisposition::MIDDLE_END_LEFT; |
| 809 | } |
| 810 | } else { |
| 811 | if (endX > 0){ |
| 812 | result.dispositionMode = LC_PointsDisposition::MIDDLE_START_LEFT; |
| 813 | } else { |
| 814 | result.dispositionMode = LC_PointsDisposition::BOTH_POINTS_ON_LEFT; |
| 815 | } |
| 816 | } |
| 817 | |
| 818 | |
| 819 | if (std::abs(endX) > std::abs(startX)){ |
| 820 | result.closestPoint = start; |
| 821 | result.farPoint = end; |
| 822 | } else { |
| 823 | result.closestPoint = end; |
| 824 | result.farPoint = start; |
| 825 | } |
| 826 | |
| 827 | |
| 828 | |
| 829 | result.snapSelectionOnLeft = snapX < 0; |
| 830 | result.startPoint = start; |
| 831 | result.endPoint = end; |
| 832 | return result; |
| 833 | } |
| 834 | |
| 835 | void LC_ActionModifyLineJoin::updateActionPrompt(){ |
| 836 | switch (getStatus()) { |
| 837 | case SetLine1: |
| 838 | updatePromptTRCancel(tr("Select first line")); |
| 839 | break; |
| 840 | case SetLine2: |
| 841 | updatePromptTRBack(tr("Select second line")); |
| 842 | break; |
| 843 | case ResolveFirstLineTrim: |
| 844 | updatePromptTRBack(tr("Select part of first line that should remain after trim")); |
| 845 | break; |
| 846 | default: |
| 847 | updatePrompt(); |
| 848 | break; |
| 849 | } |
| 850 | } |
| 851 | |
| 852 | LC_ActionOptionsWidget* LC_ActionModifyLineJoin::createOptionsWidget(){ |
| 853 | return new LC_LineJoinOptionsWidget(); |
| 854 | } |
| 855 | |
| 856 | LC_ActionOptionsPropertiesFiller* LC_ActionModifyLineJoin::createOptionsFiller() { |
| 857 | return new LC_LineJoinOptionsFiller(); |
| 858 | } |
| 859 | |
| 860 | RS2::CursorType LC_ActionModifyLineJoin::doGetMouseCursor([[maybe_unused]]int status){ |
| 861 | return RS2::SelectCursor; |
| 862 | } |
| 863 | |
| 864 | void LC_ActionModifyLineJoin::setAttributesSource(const int value){ |
| 865 | m_attributesSource = value; |
| 866 | } |
| 867 | |
| 868 | void LC_ActionModifyLineJoin::setCreatePolyline(const bool value){ |
| 869 | m_createPolyline = value; |
| 870 | } |
| 871 | |
| 872 | void LC_ActionModifyLineJoin::setRemoveOriginalLines(const bool value){ |
| 873 | m_removeOriginalLines = value; |
| 874 | } |
| 875 | |
| 876 | void LC_ActionModifyLineJoin::setLine1EdgeMode(const int value){ |
| 877 | m_line1EdgeMode = value; |
| 878 | } |
| 879 | |
| 880 | void LC_ActionModifyLineJoin::setLine2EdgeMode(const int value){ |
| 881 | m_line2EdgeMode = value; |
| 882 | } |