Revision: 76237 http://sourceforge.net/p/brlcad/code/76237 Author: starseeker Date: 2020-06-29 17:14:51 +0000 (Mon, 29 Jun 2020) Log Message: ----------- At last, got view centering to respond to a line snap. Not sure about other pieces of this - needs much more testing - but still, got first sane result from a mouse input.
Modified Paths: -------------- brlcad/trunk/include/ged/view.h brlcad/trunk/src/libged/view/snap.c brlcad/trunk/src/libtclcad/tclcad_obj.c brlcad/trunk/src/tclscripts/lib/Ged.tcl Modified: brlcad/trunk/include/ged/view.h =================================================================== --- brlcad/trunk/include/ged/view.h 2020-06-29 16:27:29 UTC (rev 76236) +++ brlcad/trunk/include/ged/view.h 2020-06-29 17:14:51 UTC (rev 76237) @@ -78,6 +78,7 @@ /* defined in grid.c */ GED_EXPORT extern int ged_snap_to_grid(struct ged *gedp, fastf_t *vx, fastf_t *vy); +GED_EXPORT extern void ged_view_center_linesnap(struct ged *gedp); /** * Grid utility command. Modified: brlcad/trunk/src/libged/view/snap.c =================================================================== --- brlcad/trunk/src/libged/view/snap.c 2020-06-29 16:27:29 UTC (rev 76236) +++ brlcad/trunk/src/libged/view/snap.c 2020-06-29 17:14:51 UTC (rev 76237) @@ -252,7 +252,6 @@ MAT4X3PNT(vp, gedp->ged_gvp->gv_model2view, out_pt); (*vx) = vp[0]; (*vy) = vp[1]; - bu_log("x, y: %g, %g\n", *vx, *vy); return 1; } @@ -259,6 +258,21 @@ return 0; } +// TODO - this is another function that belongs in libdm... +void +ged_view_center_linesnap(struct ged *gedp) +{ + point_t view_pt; + point_t model_pt; + + MAT_DELTAS_GET_NEG(model_pt, gedp->ged_gvp->gv_center); + MAT4X3PNT(view_pt, gedp->ged_gvp->gv_model2view, model_pt); + ged_snap_to_lines(gedp, &view_pt[X], &view_pt[Y]); + MAT4X3PNT(model_pt, gedp->ged_gvp->gv_view2model, view_pt); + MAT_DELTAS_VEC_NEG(gedp->ged_gvp->gv_center, model_pt); + ged_view_update(gedp->ged_gvp); +} + int ged_view_snap(struct ged *gedp, int argc, const char *argv[]) { Modified: brlcad/trunk/src/libtclcad/tclcad_obj.c =================================================================== --- brlcad/trunk/src/libtclcad/tclcad_obj.c 2020-06-29 16:27:29 UTC (rev 76236) +++ brlcad/trunk/src/libtclcad/tclcad_obj.c 2020-06-29 17:14:51 UTC (rev 76237) @@ -14348,6 +14348,10 @@ ged_grid(gedp, 2, (const char **)av); } + if (gedp->ged_gvp->gv_snap_lines) { + ged_view_center_linesnap(gedp); + } + if (0 < bu_vls_strlen(&gdvp->gdv_callback)) { Tcl_Eval(current_top->to_interp, bu_vls_addr(&gdvp->gdv_callback)); } Modified: brlcad/trunk/src/tclscripts/lib/Ged.tcl =================================================================== --- brlcad/trunk/src/tclscripts/lib/Ged.tcl 2020-06-29 16:27:29 UTC (rev 76236) +++ brlcad/trunk/src/tclscripts/lib/Ged.tcl 2020-06-29 17:14:51 UTC (rev 76237) @@ -1040,7 +1040,7 @@ } ::itcl::configbody cadwidgets::Ged::linesSnap { - #puts "called Ged::linesSnap method" + view sdata_lines snap $itk_option(-linesSnap) } ::itcl::configbody cadwidgets::Ged::mGedFile { @@ -4331,29 +4331,28 @@ # and gridSnap is active, apply snap to grid to the data point # currently being moved. - if {$point == "" && $itk_option(-gridSnap)} { - # First, get the data point being moved. - if {$mLastDataType == "data_labels" || $mLastDataType == "sdata_labels"} { - set labels [$mGed $mLastDataType $itk_component($_pane) labels] - set label [lindex $labels $mLastDataIndex] - set point [lindex $label 1] - } else { - set points [$mGed $mLastDataType $itk_component($_pane) points] - set point [lindex $points $mLastDataIndex] - } + if {$point == ""} { + if {$itk_option(-gridSnap) || $itk_option(-linesSnap)} { + # First, get the data point being moved. + if {$mLastDataType == "data_labels" || $mLastDataType == "sdata_labels"} { + set labels [$mGed $mLastDataType $itk_component($_pane) labels] + set label [lindex $labels $mLastDataIndex] + set point [lindex $label 1] + } else { + set points [$mGed $mLastDataType $itk_component($_pane) points] + set point [lindex $points $mLastDataIndex] + } - # Convert point to view coordinates and call snap_view. Then convert - # back to model coordinates. Note - vZ is saved so that the movement - # stays in a plane parallel to the view plane. - set view [pane_m2v_point $_pane $point] - set vZ [lindex $view 2] - set view [$mGed snap_view $itk_component($_pane) [lindex $view 0] [lindex $view 1]] - lappend view $vZ - set point [pane_v2m_point $_pane $view] + # Convert point to view coordinates and call snap_view. Then convert + # back to model coordinates. Note - vZ is saved so that the movement + # stays in a plane parallel to the view plane. + set view [pane_m2v_point $_pane $point] + set vZ [lindex $view 2] + set view [$mGed snap_view $itk_component($_pane) [lindex $view 0] [lindex $view 1]] + lappend view $vZ + set point [pane_v2m_point $_pane $view] + } } - if {$point == "" && !($itk_option(-gridSnap)) && $itk_option(-linesSnap)} { - puts "TODO: check for line snapping" - } # Replace the mLastDataIndex point with this point if {$point != ""} { @@ -4383,8 +4382,8 @@ ::itcl::body cadwidgets::Ged::end_data_poly_move {_pane} { refresh_off - if {$itk_option(-gridSnap)} { - # First, get the data point being moved. + if {$itk_option(-gridSnap) || $itk_option(-linesSnap)} { + # First, get the data point being moved. set point [eval $mGed data_polygons $itk_component($_pane) get_point $mLastDataIndex] # Convert point to view coordinates and call snap_view. Then convert @@ -4399,9 +4398,6 @@ # Replace the mLastDataIndex point with this point eval $mGed data_polygons $itk_component($_pane) replace_point $mLastDataIndex [list $point] } - if {!($itk_option(-gridSnap)) && $itk_option(-linesSnap)} { - puts "TODO: check for line snapping" - } if {[$mGed data_polygons $itk_component($_pane) moveall]} { foreach callback $mEndDataPolygonCallbacks { @@ -4467,15 +4463,11 @@ ::itcl::body cadwidgets::Ged::end_data_poly_circ {_pane {_button 1}} { $mGed idle_mode $itk_component($_pane) - if {$itk_option(-gridSnap)} { + if {$itk_option(-gridSnap) || $itk_option(-linesSnap)} { set mpos [$mGed get_prev_mouse $itk_component($_pane)] eval $mGed mouse_poly_circ $itk_component($_pane) $mpos } - if {!($itk_option(-gridSnap)) && $itk_option(-linesSnap)} { - puts "TODO: check for line snapping" - } - set plist [$mGed data_polygons $itk_component($_pane) polygons] set ti [$mGed data_polygons $itk_component($_pane) target_poly] incr ti @@ -4494,16 +4486,12 @@ set mpos [$mGed get_prev_mouse $itk_component($_pane)] - if {$itk_option(-gridSnap)} { + if {$itk_option(-gridSnap) || $itk_option(-linesSnap)} { set view [eval $mGed screen2view $itk_component($_pane) $mpos] set view [$mGed snap_view $itk_component($_pane) [lindex $view 0] [lindex $view 1]] set mpos [$mGed view2screen $itk_component($_pane) $view] } - if {!($itk_option(-gridSnap)) && $itk_option(-linesSnap)} { - puts "TODO: check for line snapping" - } - eval $mGed poly_cont_build $itk_component($_pane) $mpos $mGed poly_cont_build_end $itk_component($_pane) @@ -4523,15 +4511,11 @@ ::itcl::body cadwidgets::Ged::end_data_poly_ell {_pane {_button 1}} { $mGed idle_mode $itk_component($_pane) - if {$itk_option(-gridSnap)} { + if {$itk_option(-gridSnap) || $itk_option(-linesSnap)} { set mpos [$mGed get_prev_mouse $itk_component($_pane)] eval $mGed mouse_poly_ell $itk_component($_pane) $mpos } - if {!($itk_option(-gridSnap)) && $itk_option(-linesSnap)} { - puts "TODO: check for line snapping" - } - set plist [$mGed data_polygons $itk_component($_pane) polygons] set ti [$mGed data_polygons $itk_component($_pane) target_poly] incr ti @@ -4548,15 +4532,11 @@ ::itcl::body cadwidgets::Ged::end_data_poly_rect {_pane {_button 1}} { $mGed idle_mode $itk_component($_pane) - if {$itk_option(-gridSnap)} { + if {$itk_option(-gridSnap) || $itk_option(-linesSnap)} { set mpos [$mGed get_prev_mouse $itk_component($_pane)] eval $mGed mouse_poly_rect $itk_component($_pane) $mpos } - if {!($itk_option(-gridSnap)) && $itk_option(-linesSnap)} { - puts "TODO: check for line snapping" - } - set plist [$mGed data_polygons $itk_component($_pane) polygons] set ti [$mGed data_polygons $itk_component($_pane) target_poly] incr ti This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. _______________________________________________ BRL-CAD Source Commits mailing list brlcad-commits@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/brlcad-commits