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-607-g330d41cec -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/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-08-04-154929-5069-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_line.h" |
| 31 | #include "rs_pen.h" |
| 32 | #include "rs_polyline.h" |
| 33 | |
| 34 | LC_ActionModifyLineJoin::LC_ActionModifyLineJoin(LC_ActionContext *actionContext): |
| 35 | LC_AbstractActionWithPreview("ActionModifyLineJoin", actionContext, RS2::ActionModifyLineJoin){ |
| 36 | } |
| 37 | |
| 38 | LC_ActionModifyLineJoin::~LC_ActionModifyLineJoin() = default; |
| 39 | |
| 40 | void LC_ActionModifyLineJoin::doSaveOptions() { |
| 41 | save("Polyline", m_createPolyline); |
| 42 | save("RemoveOriginals", m_removeOriginalLines); |
| 43 | save("AttributesSource", m_attributesSource); |
| 44 | save("Line1EdgeMode", m_line1EdgeMode); |
| 45 | save("Line2EdgeMode", m_line2EdgeMode); |
| 46 | } |
| 47 | |
| 48 | void LC_ActionModifyLineJoin::doLoadOptions() { |
| 49 | m_createPolyline = loadBool("Polyline", false); |
| 50 | m_removeOriginalLines = loadBool("RemoveOriginals", true); |
| 51 | m_attributesSource = loadInt("AttributesSource", ATTRIBUTES_ACTIVE_PEN_LAYER); |
| 52 | m_line1EdgeMode = loadInt("Line1EdgeMode", EDGE_EXTEND_TRIM); |
| 53 | m_line2EdgeMode = loadInt("Line2EdgeMode", EDGE_EXTEND_TRIM); |
| 54 | } |
| 55 | |
| 56 | void LC_ActionModifyLineJoin::init(const int status){ |
| 57 | m_line1 = nullptr; |
| 58 | m_line2 = nullptr; |
| 59 | LC_AbstractActionWithPreview::init(status); |
| 60 | } |
| 61 | |
| 62 | void LC_ActionModifyLineJoin::doInitWithContextEntity(RS_Entity* contextEntity, const RS_Vector& clickPos) { |
| 63 | if (isLine(contextEntity)) { |
| 64 | m_line1 = static_cast<RS_Line*>(contextEntity); |
| 65 | m_line1ClickPosition = contextEntity->getNearestPointOnEntity(clickPos, true); |
| 66 | setStatus(SetLine2); |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | |
| 71 | |
| 72 | |
| 73 | RS_Line *LC_ActionModifyLineJoin::catchLine(const LC_MouseEvent *e, const bool forPreview) const { |
| 74 | RS_Entity *en = forPreview ? catchModifiableAndDescribe(e, m_lineType) :catchModifiableEntity(e, m_lineType); |
| 75 | RS_Line *snappedLine = nullptr; |
| 76 | if (isLine(en)){ |
| 77 | snappedLine = dynamic_cast<RS_Line *>(en); |
| 78 | } |
| 79 | return snappedLine; |
| 80 | } |
| 81 | |
| 82 | void LC_ActionModifyLineJoin::drawSnapper() { |
| 83 | |
| 84 | } |
| 85 | |
| 86 | void LC_ActionModifyLineJoin::doPreparePreviewEntities(const LC_MouseEvent* e, [[maybe_unused]]RS_Vector &snap, QList<RS_Entity *> &list, const int status){ |
| 87 | const RS_Line *snappedLine = catchLine(e, true); |
| 88 | switch (status) { |
| 89 | case SetLine1: { |
| 90 | if (snappedLine != nullptr){ |
| 91 | highlightHover(snappedLine); |
| 92 | } |
| 93 | break; |
| 94 | } |
| 95 | case SetLine2: { |
| 96 | if (snappedLine == m_line1){ |
| 97 | snappedLine = nullptr; |
| 98 | } |
| 99 | highlightSelected(m_line1); |
| 100 | if (snappedLine != nullptr){ |
| 101 | highlightHover(snappedLine); |
| 102 | |
| 103 | const RS_Vector coord = e->graphPoint; |
| 104 | const LC_LineJoinData *lineJoinData = createLineJoinData(snappedLine, coord); |
| 105 | if (lineJoinData != nullptr){ |
| 106 | RS_Polyline *polyline = lineJoinData->polyline; |
| 107 | if (polyline != nullptr){ |
| 108 | list << polyline; |
| 109 | } |
| 110 | |
| 111 | if (m_showRefEntitiesOnPreview) { |
| 112 | if (!lineJoinData->parallelLines) { |
| 113 | const RS_Vector &intersectionPoint = lineJoinData->intersectPoint; |
| 114 | createRefPoint(intersectionPoint, list); |
| 115 | } |
| 116 | |
| 117 | const RS_Vector &major1 = lineJoinData->majorPointLine1; |
| 118 | if (major1.valid) { |
| 119 | createRefPoint(major1, list); |
| 120 | } |
| 121 | |
| 122 | const RS_Vector &major2 = lineJoinData->majorPointLine2; |
| 123 | if (major2.valid) { |
| 124 | createRefPoint(major2, list); |
| 125 | } |
| 126 | } |
| 127 | |
| 128 | if (isInfoCursorForModificationEnabled()){ |
| 129 | auto builder = msgStart() |
| 130 | .string(tr("Lines Join")); |
| 131 | if (lineJoinData->parallelLines) { |
| 132 | builder.add(tr("Lines are parallel")); |
| 133 | } |
| 134 | else{ |
| 135 | builder.vector(tr("Intersection:"), lineJoinData->intersectPoint); |
| 136 | } |
| 137 | builder.toInfoCursorZone2(false); |
| 138 | } |
| 139 | |
| 140 | |
| 141 | delete lineJoinData; |
| 142 | } |
| 143 | } |
| 144 | break; |
| 145 | } |
| 146 | case ResolveFirstLineTrim: { |
| 147 | if (snappedLine != m_line1){ |
| 148 | |
| 149 | |
| 150 | snappedLine = nullptr; |
| 151 | } |
| 152 | highlightSelected(m_line1); |
| 153 | if (snappedLine != nullptr){ |
| 154 | |
| 155 | |
| 156 | const RS_Vector coord = e->graphPoint; |
| 157 | updateLine1TrimData(coord); |
| 158 | |
| 159 | const RS_Polyline *polyline = m_linesJoinData->polyline; |
| 160 | if (polyline != nullptr){ |
| 161 | list << polyline->clone(); |
| 162 | if (m_showRefEntitiesOnPreview) { |
| 163 | if (!m_linesJoinData->parallelLines) { |
| 164 | const RS_Vector &intersectionPoint = m_linesJoinData->intersectPoint; |
| 165 | createRefPoint(intersectionPoint, list); |
| 166 | } |
| 167 | createRefPoint(m_linesJoinData->majorPointLine1, list); |
| 168 | createRefPoint(m_linesJoinData->majorPointLine2, list); |
| 169 | } |
| 170 | } |
| 171 | } |
| 172 | break; |
| 173 | } |
| 174 | default: |
| 175 | break; |
| 176 | } |
| 177 | } |
| 178 | |
| 179 | void LC_ActionModifyLineJoin::doOnLeftMouseButtonRelease(const LC_MouseEvent* e, const int status, [[maybe_unused]]const RS_Vector &snapPoint){ |
| 180 | RS_Line *snappedLine = catchLine(e, false); |
| 181 | switch (status) { |
| 1 | Control jumps to 'case ResolveFirstLineTrim:' at line 245 | |
|
| 182 | case SetLine1: { |
| 183 | if (snappedLine != nullptr){ |
| 184 | m_line1 = snappedLine; |
| 185 | m_line1ClickPosition = snapPoint; |
| 186 | setStatus(SetLine2); |
| 187 | } else { |
| 188 | commandMessage(tr("No line selected")); |
| 189 | } |
| 190 | break; |
| 191 | } |
| 192 | case SetLine2: { |
| 193 | if (snappedLine == m_line1){ |
| 194 | snappedLine = nullptr; |
| 195 | } |
| 196 | if (snappedLine != nullptr){ |
| 197 | m_line2 = snappedLine; |
| 198 | const RS_Vector snap = e->graphPoint; |
| 199 | LC_LineJoinData *joinData = createLineJoinData(snappedLine, snap); |
| 200 | if (joinData != nullptr){ |
| 201 | |
| 202 | if (joinData->parallelLines){ |
| 203 | |
| 204 | if (joinData->straightLinesConnection){ |
| 205 | |
| 206 | m_linesJoinData = joinData; |
| 207 | trigger(); |
| 208 | } else { |
| 209 | delete joinData; |
| 210 | commandMessage(tr("Lines are parallel, can't merge")); |
| 211 | } |
| 212 | } else { |
| 213 | if (joinData->areLinesAlreadyIntersected()){ |
| 214 | |
| 215 | commandMessage(tr("Lines already intersects, can't merge")); |
| 216 | delete joinData; |
| 217 | } else { |
| 218 | |
| 219 | |
| 220 | |
| 221 | |
| 222 | |
| 223 | bool firstLineTrimShouldBeSpecified = joinData->isIntersectionOnLine1(); |
| 224 | if (m_line1EdgeMode != EDGE_EXTEND_TRIM){ |
| 225 | firstLineTrimShouldBeSpecified = false; |
| 226 | } |
| 227 | m_linesJoinData = joinData; |
| 228 | if (firstLineTrimShouldBeSpecified){ |
| 229 | |
| 230 | setStatus(ResolveFirstLineTrim); |
| 231 | highlightEntity(m_line1); |
| 232 | redraw(); |
| 233 | } else { |
| 234 | |
| 235 | trigger(); |
| 236 | } |
| 237 | } |
| 238 | } |
| 239 | } else { |
| 240 | commandMessage(tr("No line selected")); |
| 241 | } |
| 242 | } |
| 243 | break; |
| 244 | } |
| 245 | case ResolveFirstLineTrim: { |
| 246 | if (snappedLine == m_line1){ |
| 2 | | Assuming 'snappedLine' is equal to field 'm_line1' | |
|
| |
| 247 | const RS_Vector snap = e->graphPoint; |
| 248 | |
| 249 | updateLine1TrimData(snap); |
| 4 | | Calling 'LC_ActionModifyLineJoin::updateLine1TrimData' | |
|
| 250 | |
| 251 | const RS_Polyline *polyline = m_linesJoinData->polyline; |
| 252 | if (polyline != nullptr){ |
| 253 | trigger(); |
| 254 | } |
| 255 | } else { |
| 256 | highlightEntity(m_line1); |
| 257 | } |
| 258 | break; |
| 259 | } |
| 260 | default: |
| 261 | break; |
| 262 | } |
| 263 | } |
| 264 | |
| 265 | void LC_ActionModifyLineJoin::doBack(const LC_MouseEvent* e, const int status){ |
| 266 | LC_AbstractActionWithPreview::doBack(e, status); |
| 267 | switch (status) { |
| 268 | case SetLine1: |
| 269 | init(SetLine1 - 1); |
| 270 | break; |
| 271 | case SetLine2: { |
| 272 | setStatus(SetLine1); |
| 273 | break; |
| 274 | } |
| 275 | case ResolveFirstLineTrim: { |
| 276 | setStatus(SetLine2); |
| 277 | break; |
| 278 | } |
| 279 | default: |
| 280 | initPrevious(status); |
| 281 | break; |
| 282 | } |
| 283 | } |
| 284 | |
| 285 | void LC_ActionModifyLineJoin::doAfterTrigger(){ |
| 286 | LC_AbstractActionWithPreview::doAfterTrigger(); |
| 287 | delete m_linesJoinData; |
| 288 | m_linesJoinData = nullptr; |
| 289 | redraw(); |
| 290 | |
| 291 | init(SetLine1); |
| 292 | } |
| 293 | |
| 294 | bool LC_ActionModifyLineJoin::doCheckMayTrigger(){ |
| 295 | return m_linesJoinData != nullptr; |
| 296 | } |
| 297 | |
| 298 | bool LC_ActionModifyLineJoin::isSetActivePenAndLayerOnTrigger(){ |
| 299 | |
| 300 | return false; |
| 301 | } |
| 302 | |
| 303 | bool LC_ActionModifyLineJoin::doTriggerEntitiesPrepare(LC_DocumentModificationBatch& ctx){ |
| 304 | if (m_linesJoinData->parallelLines && m_linesJoinData->straightLinesConnection){ |
| 305 | |
| 306 | auto *line = createLine(m_linesJoinData->majorPointLine1, m_linesJoinData->majorPointLine2, ctx.entitiesToAdd); |
| 307 | |
| 308 | applyAttributes(line, true); |
| 309 | } else { |
| 310 | |
| 311 | const RS_Vector &intersectionPoint = m_linesJoinData->intersectPoint; |
| 312 | |
| 313 | |
| 314 | |
| 315 | const RS_Vector &major1 = m_linesJoinData->majorPointLine1; |
| 316 | const RS_Vector &major2 = m_linesJoinData->majorPointLine2; |
| 317 | |
| 318 | if (m_createPolyline && major1.valid && major2.valid){ |
| 319 | auto *poly = new RS_Polyline(m_document); |
| 320 | poly->addVertex(major1); |
| 321 | poly->addVertex(intersectionPoint); |
| 322 | poly->addVertex(major2); |
| 323 | applyAttributes(poly, true); |
| 324 | ctx += poly; |
| 325 | |
| 326 | } else { |
| 327 | if (major1.valid){ |
| 328 | |
| 329 | RS_Line* l1 = createLine(major1, intersectionPoint, ctx.entitiesToAdd); |
| 330 | applyAttributes(l1, true); |
| 331 | } |
| 332 | if (major2.valid){ |
| 333 | |
| 334 | RS_Line* l2 = createLine(intersectionPoint, major2, ctx.entitiesToAdd); |
| 335 | applyAttributes(l2, false); |
| 336 | } |
| 337 | } |
| 338 | } |
| 339 | |
| 340 | if (m_removeOriginalLines){ |
| 341 | |
| 342 | if (m_line1EdgeMode == EDGE_EXTEND_TRIM){ |
| 343 | ctx -= m_line1; |
| 344 | } |
| 345 | |
| 346 | if (m_line2EdgeMode == EDGE_EXTEND_TRIM){ |
| 347 | ctx -= m_line2; |
| 348 | } |
| 349 | } |
| 350 | return true; |
| 351 | } |
| 352 | |
| 353 | |
| 354 | |
| 355 | |
| 356 | |
| 357 | |
| 358 | void LC_ActionModifyLineJoin::applyAttributes(RS_Entity *e, bool forLine1){ |
| 359 | RS_Pen pen; |
| 360 | RS_Layer *layer = nullptr; |
| 361 | switch (m_attributesSource) { |
| 362 | case ATTRIBUTES_LINE_1: { |
| 363 | pen = m_line1->getPen(false); |
| 364 | e->setPen(pen); |
| 365 | layer = m_line1->getLayer(true); |
| 366 | e->setLayer(layer); |
| 367 | break; |
| 368 | } |
| 369 | case ATTRIBUTES_BOTH_LINES: { |
| 370 | |
| 371 | if (forLine1){ |
| 372 | pen = m_line1->getPen(false); |
| 373 | e->setPen(pen); |
| 374 | layer = m_line1->getLayer(true); |
| 375 | e->setLayer(layer); |
| 376 | } else { |
| 377 | pen = m_line2->getPen(false); |
| 378 | e->setPen(pen); |
| 379 | layer = m_line2->getLayer(true); |
| 380 | e->setLayer(layer); |
| 381 | } |
| 382 | break; |
| 383 | } |
| 384 | case ATTRIBUTES_LINE_2: { |
| 385 | |
| 386 | pen = m_line2->getPen(false); |
| 387 | e->setPen(pen); |
| 388 | layer = m_line2->getLayer(true); |
| 389 | e->setLayer(layer); |
| 390 | break; |
| 391 | } |
| 392 | case ATTRIBUTES_ACTIVE_PEN_LAYER: { |
| 393 | |
| 394 | setPenAndLayerToActive(e); |
| 395 | break; |
| 396 | } |
| 397 | default: |
| 398 | break; |
| 399 | } |
| 400 | } |
| 401 | |
| 402 | |
| 403 | |
| 404 | |
| 405 | |
| 406 | |
| 407 | |
| 408 | LC_ActionModifyLineJoin::LC_LineJoinData *LC_ActionModifyLineJoin::createLineJoinData(const RS_Line *secondLine, const RS_Vector &snapPoint) const { |
| 409 | LC_LineJoinData *result = nullptr; |
| 410 | |
| 411 | if (m_line1 != nullptr && secondLine != nullptr){ |
| 412 | |
| 413 | |
| 414 | const RS_Vector line1Start = m_line1->getStartpoint(); |
| 415 | const RS_Vector line1End = m_line1->getEndpoint(); |
| 416 | const RS_Vector line2Start = secondLine->getStartpoint(); |
| 417 | const RS_Vector line2End = secondLine->getEndpoint(); |
| 418 | |
| 419 | const RS_Vector intersection = LC_LineMath::getIntersectionLineLine(line1Start, line1End, line2Start, line2End); |
| 420 | |
| 421 | |
| 422 | if (intersection.valid){ |
| 423 | result = proceedNonParallelLines(m_line1ClickPosition, snapPoint, intersection, line1Start, line1End, line2Start, line2End); |
| 424 | |
| 425 | } else { |
| 426 | result = proceedParallelLinesJoin(line1Start, line1End, line2Start, line2End); |
| 427 | } |
| 428 | } |
| 429 | return result; |
| 430 | } |
| 431 | |
| 432 | |
| 433 | |
| 434 | |
| 435 | |
| 436 | |
| 437 | |
| 438 | |
| 439 | |
| 440 | |
| 441 | |
| 442 | |
| 443 | LC_ActionModifyLineJoin::LC_LineJoinData *LC_ActionModifyLineJoin::proceedNonParallelLines(const RS_Vector& line1ClickPoint, const RS_Vector &snapPoint, |
| 444 | const RS_Vector &intersectPoint, |
| 445 | const RS_Vector &line1Start, const RS_Vector &line1End, |
| 446 | const RS_Vector &line2Start, const RS_Vector &line2End) const { |
| 447 | auto *result = new LC_LineJoinData(); |
| 448 | |
| 449 | result->intersectPoint = intersectPoint; |
| 450 | result->parallelLines = false; |
| 451 | |
| 452 | |
| 453 | auto *polyline = new RS_Polyline(m_document); |
| 454 | |
| 455 | |
| 456 | |
| 457 | const LC_PointsDisposition line1Disposition = determine3PointsDisposition(line1Start, line1End, intersectPoint, line1ClickPoint); |
| 458 | |
| 459 | |
| 460 | |
| 461 | |
| 462 | const RS_Vector pointFromLine1 = getMajorPointFromLine(m_line1EdgeMode, line1Start, line1End, line1Disposition); |
| 463 | result->majorPointLine1 = pointFromLine1; |
| 464 | |
| 465 | |
| 466 | if (pointFromLine1.valid){ |
| 467 | polyline->addVertex(pointFromLine1); |
| 468 | } |
| 469 | |
| 470 | |
| 471 | polyline->addVertex(intersectPoint); |
| 472 | |
| 473 | |
| 474 | |
| 475 | const LC_PointsDisposition line2Disposition = determine3PointsDisposition(line2Start, line2End, intersectPoint, snapPoint); |
| 476 | |
| 477 | |
| 478 | const RS_Vector pointFromLine2 = getMajorPointFromLine(m_line2EdgeMode, line2Start, line2End, line2Disposition); |
| 479 | result->majorPointLine2 = pointFromLine2; |
| 480 | |
| 481 | |
| 482 | if (pointFromLine2.valid){ |
| 483 | polyline->addVertex(pointFromLine2); |
| 484 | } |
| 485 | |
| 486 | |
| 487 | result->polyline = polyline; |
| 488 | result->line1Disposition = line1Disposition; |
| 489 | result->line2Disposition = line2Disposition; |
| 490 | result->intersectPoint = intersectPoint; |
| 491 | return result; |
| 492 | } |
| 493 | |
| 494 | |
| 495 | |
| 496 | |
| 497 | |
| 498 | |
| 499 | void LC_ActionModifyLineJoin::updateLine1TrimData(const RS_Vector& snap) const { |
| 500 | |
| 501 | const RS_Vector &line1Start = m_line1->getStartpoint(); |
| 5 | | Called C++ object pointer is null |
|
| 502 | const RS_Vector &line1End = m_line1->getEndpoint(); |
| 503 | RS_Polyline *polyline = m_linesJoinData->polyline; |
| 504 | |
| 505 | delete polyline; |
| 506 | |
| 507 | polyline = new RS_Polyline(m_document); |
| 508 | m_linesJoinData->polyline = polyline; |
| 509 | |
| 510 | const RS_Vector &intersection = m_linesJoinData->intersectPoint; |
| 511 | |
| 512 | |
| 513 | const LC_PointsDisposition line1Disposition = determine3PointsDisposition(line1Start, line1End, intersection, snap); |
| 514 | |
| 515 | |
| 516 | const RS_Vector pointFromLine1 = getMajorPointFromLine(m_line1EdgeMode, line1Start, line1End, line1Disposition); |
| 517 | m_linesJoinData->majorPointLine1 = pointFromLine1; |
| 518 | |
| 519 | |
| 520 | if (line1Start.valid){ |
| 521 | polyline->addVertex(pointFromLine1); |
| 522 | } |
| 523 | |
| 524 | |
| 525 | polyline->addVertex(intersection); |
| 526 | |
| 527 | |
| 528 | const RS_Vector pointFromLine2 = getMajorPointFromLine(m_line2EdgeMode, m_line2->getStartpoint(), m_line2->getEndpoint(), m_linesJoinData->line2Disposition); |
| 529 | m_linesJoinData->majorPointLine2 = pointFromLine2; |
| 530 | |
| 531 | |
| 532 | if (pointFromLine2.valid){ |
| 533 | polyline->addVertex(pointFromLine2); |
| 534 | } |
| 535 | } |
| 536 | |
| 537 | |
| 538 | |
| 539 | |
| 540 | |
| 541 | |
| 542 | |
| 543 | |
| 544 | |
| 545 | |
| 546 | RS_Vector LC_ActionModifyLineJoin::getMajorPointFromLine( |
| 547 | const int edgeMode, |
| 548 | const RS_Vector &lineStart, |
| 549 | const RS_Vector &lineEnd, |
| 550 | const LC_PointsDisposition &lineDisposition) const{ |
| 551 | auto result = RS_Vector(false); |
| 552 | switch (edgeMode) { |
| 553 | case EDGE_EXTEND_TRIM: |
| 554 | switch (lineDisposition.dispositionMode) { |
| 555 | case LC_PointsDisposition::BOTH_POINTS_ON_RIGHT: |
| 556 | case LC_PointsDisposition::BOTH_POINTS_ON_LEFT: { |
| 557 | result = lineDisposition.farPoint; |
| 558 | break; |
| 559 | } |
| 560 | case LC_PointsDisposition::MIDDLE_END_LEFT: { |
| 561 | if (lineDisposition.snapSelectionOnLeft){ |
| 562 | result = lineEnd; |
| 563 | } else { |
| 564 | result = lineStart; |
| 565 | } |
| 566 | break; |
| 567 | } |
| 568 | case LC_PointsDisposition::MIDDLE_START_LEFT: { |
| 569 | if (lineDisposition.snapSelectionOnLeft){ |
| 570 | result = lineStart; |
| 571 | } else { |
| 572 | result = lineEnd; |
| 573 | } |
| 574 | break; |
| 575 | } |
| 576 | default: |
| 577 | break; |
| 578 | } |
| 579 | break; |
| 580 | case EDGE_ADD_SEGMENT: |
| 581 | switch (lineDisposition.dispositionMode) { |
| 582 | case LC_PointsDisposition::BOTH_POINTS_ON_RIGHT: |
| 583 | case LC_PointsDisposition::BOTH_POINTS_ON_LEFT: { |
| 584 | |
| 585 | |
| 586 | result = lineDisposition.closestPoint; |
| 587 | break; |
| 588 | } |
| 589 | case LC_PointsDisposition::MIDDLE_END_LEFT: |
| 590 | case LC_PointsDisposition::MIDDLE_START_LEFT: { |
| 591 | |
| 592 | |
| 593 | break; |
| 594 | } |
| 595 | default: |
| 596 | break; |
| 597 | } |
| 598 | break; |
| 599 | case EDGE_NO_MODIFICATION: |
| 600 | break; |
| 601 | default: |
| 602 | break; |
| 603 | } |
| 604 | return result; |
| 605 | } |
| 606 | |
| 607 | |
| 608 | |
| 609 | |
| 610 | |
| 611 | |
| 612 | |
| 613 | |
| 614 | |
| 615 | LC_ActionModifyLineJoin::LC_LineJoinData *LC_ActionModifyLineJoin::proceedParallelLinesJoin( |
| 616 | const RS_Vector &line1Start, const RS_Vector &line1End, |
| 617 | const RS_Vector &line2Start, const RS_Vector &line2End) const{ |
| 618 | |
| 619 | auto result = new LC_LineJoinData(); |
| 620 | result->parallelLines = true; |
| 621 | |
| 622 | |
| 623 | bool sameRay = LC_LineMath::areLinesOnSameRay(line1Start, line1End, line2Start, line2End); |
| 624 | |
| 625 | if (sameRay){ |
| 626 | result->straightLinesConnection = true; |
| 627 | |
| 628 | |
| 629 | |
| 630 | double angle = line1Start.angleTo(line1End); |
| 631 | |
| 632 | |
| 633 | auto startOnX1 = RS_Vector(line1Start); |
| 634 | auto endOnX1 = RS_Vector(line1End); |
| 635 | auto startOnX2 = RS_Vector(line2Start); |
| 636 | auto endOnX2 = RS_Vector(line2End); |
| 637 | |
| 638 | |
| 639 | endOnX1.rotate(startOnX1, -angle); |
| 640 | startOnX2.rotate(startOnX1, -angle); |
| 641 | endOnX2.rotate(startOnX1, -angle); |
| 642 | |
| 643 | |
| 644 | double sx1 = startOnX1.x; |
| 645 | double ex1 = endOnX1.x; |
| 646 | double sx2 = startOnX2.x; |
| 647 | double ex2 = endOnX2.x; |
| 648 | |
| 649 | |
| 650 | |
| 651 | RS_Vector s1 = line1Start; |
| 652 | RS_Vector e1 = line1End; |
| 653 | RS_Vector s2 = line2Start; |
| 654 | RS_Vector e2 = line2End; |
| 655 | |
| 656 | |
| 657 | |
| 658 | |
| 659 | |
| 660 | |
| 661 | |
| 662 | if (ex1 < sx1){ |
| 663 | std::swap(sx1, ex1); |
| 664 | std::swap(s1, e1); |
| 665 | } |
| 666 | |
| 667 | if (ex2 < sx2){ |
| 668 | std::swap(sx2, ex2); |
| 669 | std::swap(s2, e2); |
| 670 | } |
| 671 | |
| 672 | RS_Vector leftPoint; |
| 673 | RS_Vector rightPoint; |
| 674 | RS_Vector middleLeftPoint; |
| 675 | RS_Vector middleRightPoint; |
| 676 | |
| 677 | |
| 678 | bool hasIntersection = false; |
| 679 | |
| 680 | if (sx1 < sx2){ |
| 681 | hasIntersection = sx2 < ex1; |
| 682 | leftPoint = s1; |
| 683 | if (hasIntersection){ |
| 684 | if (ex1 > ex2){ |
| 685 | rightPoint = e1; |
| 686 | } else { |
| 687 | rightPoint = e2; |
| 688 | } |
| 689 | } else { |
| 690 | rightPoint = e2; |
| 691 | middleLeftPoint = e1; |
| 692 | middleRightPoint = s2; |
| 693 | } |
| 694 | } else { |
| 695 | hasIntersection = sx1 < ex2; |
| 696 | leftPoint = s2; |
| 697 | if (hasIntersection){ |
| 698 | if (ex1 > ex2){ |
| 699 | rightPoint = e1; |
| 700 | } else { |
| 701 | rightPoint = e2; |
| 702 | } |
| 703 | } else { |
| 704 | rightPoint = e1; |
| 705 | middleRightPoint = s1; |
| 706 | middleLeftPoint = e2; |
| 707 | } |
| 708 | } |
| 709 | |
| 710 | |
| 711 | |
| 712 | |
| 713 | if (m_line1EdgeMode == EDGE_EXTEND_TRIM || m_line2EdgeMode == EDGE_EXTEND_TRIM){ |
| 714 | auto *polyline = new RS_Polyline(m_document); |
| 715 | |
| 716 | |
| 717 | polyline->addVertex(leftPoint); |
| 718 | polyline->addVertex(rightPoint); |
| 719 | |
| 720 | |
| 721 | |
| 722 | |
| 723 | |
| 724 | |
| 725 | result->majorPointLine1 = leftPoint; |
| 726 | result->majorPointLine2 = rightPoint; |
| 727 | |
| 728 | result->polyline = polyline; |
| 729 | } else if (m_line1EdgeMode == EDGE_ADD_SEGMENT && m_line2EdgeMode == EDGE_ADD_SEGMENT){ |
| 730 | |
| 731 | |
| 732 | if (!hasIntersection){ |
| 733 | |
| 734 | auto *polyline = new RS_Polyline(m_document); |
| 735 | |
| 736 | |
| 737 | polyline->addVertex(middleLeftPoint); |
| 738 | polyline->addVertex(middleRightPoint); |
| 739 | |
| 740 | |
| 741 | result->majorPointLine1 = middleLeftPoint; |
| 742 | result->majorPointLine2 = middleRightPoint; |
| 743 | result->polyline = polyline; |
| 744 | } |
| 745 | } |
| 746 | } else { |
| 747 | result->straightLinesConnection = false; |
| 748 | } |
| 749 | return result; |
| 750 | } |
| 751 | |
| 752 | |
| 753 | |
| 754 | |
| 755 | |
| 756 | |
| 757 | |
| 758 | |
| 759 | |
| 760 | |
| 761 | LC_ActionModifyLineJoin::LC_PointsDisposition LC_ActionModifyLineJoin::determine3PointsDisposition( |
| 762 | const RS_Vector& start, |
| 763 | const RS_Vector& end, |
| 764 | const RS_Vector& intersection, |
| 765 | const RS_Vector &snapPoint) const{ |
| 766 | |
| 767 | |
| 768 | |
| 769 | |
| 770 | const double angle = start.angleTo(end); |
| 771 | |
| 772 | |
| 773 | auto startOnX = RS_Vector(start); |
| 774 | auto endOnX = RS_Vector(end); |
| 775 | |
| 776 | startOnX.rotate(intersection, -angle); |
| 777 | endOnX.rotate(intersection, -angle); |
| 778 | |
| 779 | |
| 780 | RS_Vector snapProjection = LC_LineMath::getNearestPointOnInfiniteLine(snapPoint, start, end); |
| 781 | |
| 782 | |
| 783 | const RS_Vector snapOnX = snapProjection.rotate(intersection, -angle); |
| 784 | |
| 785 | |
| 786 | |
| 787 | const double ix = intersection.x; |
| 788 | const double delta = ix; |
| 789 | |
| 790 | |
| 791 | double startX = startOnX.x; |
| 792 | double endX = endOnX.x; |
| 793 | double snapX = snapOnX.x; |
| 794 | |
| 795 | startX -= delta; |
| 796 | endX -= delta; |
| 797 | snapX -= delta; |
| 798 | |
| 799 | LC_PointsDisposition result; |
| 800 | |
| 801 | |
| 802 | if (startX > 0){ |
| 803 | if (endX > 0){ |
| 804 | result.dispositionMode = LC_PointsDisposition::BOTH_POINTS_ON_RIGHT; |
| 805 | } else { |
| 806 | result.dispositionMode = LC_PointsDisposition::MIDDLE_END_LEFT; |
| 807 | } |
| 808 | } else { |
| 809 | if (endX > 0){ |
| 810 | result.dispositionMode = LC_PointsDisposition::MIDDLE_START_LEFT; |
| 811 | } else { |
| 812 | result.dispositionMode = LC_PointsDisposition::BOTH_POINTS_ON_LEFT; |
| 813 | } |
| 814 | } |
| 815 | |
| 816 | |
| 817 | if (std::abs(endX) > std::abs(startX)){ |
| 818 | result.closestPoint = start; |
| 819 | result.farPoint = end; |
| 820 | } else { |
| 821 | result.closestPoint = end; |
| 822 | result.farPoint = start; |
| 823 | } |
| 824 | |
| 825 | |
| 826 | |
| 827 | result.snapSelectionOnLeft = snapX < 0; |
| 828 | result.startPoint = start; |
| 829 | result.endPoint = end; |
| 830 | return result; |
| 831 | } |
| 832 | |
| 833 | void LC_ActionModifyLineJoin::updateActionPrompt(){ |
| 834 | switch (getStatus()) { |
| 835 | case SetLine1: |
| 836 | updatePromptTRCancel(tr("Select first line")); |
| 837 | break; |
| 838 | case SetLine2: |
| 839 | updatePromptTRBack(tr("Select second line")); |
| 840 | break; |
| 841 | case ResolveFirstLineTrim: |
| 842 | updatePromptTRBack(tr("Select part of first line that should remain after trim")); |
| 843 | break; |
| 844 | default: |
| 845 | updatePrompt(); |
| 846 | break; |
| 847 | } |
| 848 | } |
| 849 | |
| 850 | LC_ActionOptionsWidget* LC_ActionModifyLineJoin::createOptionsWidget(){ |
| 851 | return new LC_LineJoinOptionsWidget(); |
| 852 | } |
| 853 | |
| 854 | LC_ActionOptionsPropertiesFiller* LC_ActionModifyLineJoin::createOptionsFiller() { |
| 855 | return new LC_LineJoinOptionsFiller(); |
| 856 | } |
| 857 | |
| 858 | RS2::CursorType LC_ActionModifyLineJoin::doGetMouseCursor([[maybe_unused]]int status){ |
| 859 | return RS2::SelectCursor; |
| 860 | } |
| 861 | |
| 862 | void LC_ActionModifyLineJoin::setAttributesSource(const int value){ |
| 863 | m_attributesSource = value; |
| 864 | } |
| 865 | |
| 866 | void LC_ActionModifyLineJoin::setCreatePolyline(const bool value){ |
| 867 | m_createPolyline = value; |
| 868 | } |
| 869 | |
| 870 | void LC_ActionModifyLineJoin::setRemoveOriginalLines(const bool value){ |
| 871 | m_removeOriginalLines = value; |
| 872 | } |
| 873 | |
| 874 | void LC_ActionModifyLineJoin::setLine1EdgeMode(const int value){ |
| 875 | m_line1EdgeMode = value; |
| 876 | } |
| 877 | |
| 878 | void LC_ActionModifyLineJoin::setLine2EdgeMode(const int value){ |
| 879 | m_line2EdgeMode = value; |
| 880 | } |