int CIRCLE_WIDGET::stroke_cb(CGESTUREptr& g, DrawState*&) { err_adv(debug_all, "CIRCLE_WIDGET::stroke_cb()"); // Activity occurred to extend the deadline for fading away: reset_timeout(); // sanity check assert(g); if( !g->is_line() ) return 1; _preview.update_length(); if (PIXEL_list(_preview).dist(g->start()) < PIXEL_DIST_THRESH || g->start().dist(_center) < PIXEL_DIST_THRESH ) { if ( _circle ) { Bcurve *border = Bcurve::lookup(_circle->bfaces().get_boundary().edges()); if ( border != 0 ) { Wplane plane = border->plane(); _radius = _center.dist(Wpt(plane, Wline(XYpt(g->end())))); } } else { Wplane P = get_draw_plane(g->end()); if (!P.is_valid()) return 1; _radius = _center.dist(Wpt(P, Wline(XYpt(g->end())))); } make_preview(); } return 1; }
int CIRCLE_WIDGET::tap_cb(CGESTUREptr& g, DrawState*& s) { err_adv(debug_all, "CIRCLE_WIDGET::tap_cb()"); PIXEL pdummy; int idummy; if( _suggest_active ) { _preview.update_length(); _literal_shape.update_length(); double preview_dist = PIXEL_list(_preview).closest( PIXEL(g->start()), pdummy, idummy ); double literal_dist = PIXEL_list(_literal_shape).closest( PIXEL(g->start()), pdummy, idummy ); if( preview_dist < literal_dist && preview_dist < PIXEL_DIST_THRESH ) { _suggest_active = false; make_preview(); return 1; } else if( literal_dist < preview_dist && literal_dist < PIXEL_DIST_THRESH ) { finish_literal(); return cancel_cb(g,s); } else { return cancel_cb(g,s); } } if (_cmd) WORLD::add_command(_cmd); return cancel_cb(g,s); }
int SELECT_WIDGET::tap_cb(CGESTUREptr& g, DrawState*& s) { err_adv(debug, "SELECT_WIDGET::tap_cb()"); assert(g && g->is_tap()); if (_mode==SLASH_SEL) { //pattern editing Bface* f = find_face(g->start(),0.25,MIN_PIX_AREA); if (f) { if (select_list.contains(f)||select_list.contains(f->quad_partner())) { //get whichever part of the quad is in the selection list int temp = select_list.contains(f) ? select_list.get_index(f)+1 : select_list.get_index(f->quad_partner())+1 ; if (temp>end_face) //user selected the end face { end_face=temp; } else //user is selecting a pattern { if (pattern<temp) pattern=temp; //select/deselect face if (temp < MAX_PATTERN_SIZE) pattern_array[temp]=!pattern_array[temp]; } return 1; } else cerr << "tap found a NULL face !" << endl; } return cancel_cb(g,s); } else { // Tap a selected face near the middle to deselect it: if (try_deselect_face(g->center(), 0.25)) return 1; // Tap edge to deselect if (try_deselect_edge(g->center())) return 1; } // Otherwise, turn off SELECT_WIDGET return cancel_cb(g,s); }
//! Given a set of enclosed face, activate the widget to sweep out a //! shape. Checks for errors, returns true on success. bool SWEEP_DISK::setup(CGESTUREptr& gest, double dur) { static bool debug = Config::get_var_bool("DEBUG_SWEEP_SETUP",false) || debug_all; if (!(gest && gest->is_dslash())) { err_adv(debug, "SWEEP_DISK::setup: bad gesture"); return false; } // XXX - shouldn't require it is a Panel: Panel* p = dynamic_cast<Panel*>(Bsurface::hit_ctrl_surface(gest->start())); if (!p) { err_adv(debug, "SWEEP_DISK::setup: non-panel"); return false; } Bface_list faces = p->bfaces(); _boundary = faces.get_boundary(); if (_boundary.num_line_strips() != 1) { err_adv(debug, "SWEEP_DISK::setup: error: boundary is not a single piece"); return false; } // Get the best-fit plane, rejecting if the boundary Wpt_list // doesn't lie within 0.1 of its total length from the plane: if (!_boundary.verts().pts().get_plane(_plane, 0.1)) { err_adv(debug,"SWEEP_DISK::setup: Error: can't find plane"); return false; } // Find the center Wpt o = _boundary.verts().pts().average(); // decide guideline direction (normal to plane): Wvec n = _plane.normal(); if (VIEW::eye_vec(o) * n > 0) n = -n; // decide the length for the guideline: double len = world_length(o, GUIDE_LEN); // compute guideline endpoint: Wpt b = o + n.normalized()*len; // try basic setup if (!SWEEP_BASE::setup(dynamic_pointer_cast<LMESH>(faces.mesh()), o, b, dur)) return false; // ******** From here on we accept it ******** _enclosed_faces = faces; return true; }
int INFLATE::stroke_cb(CGESTUREptr& gest, DrawState*& s) { err_adv(debug, "INFLATE::stroke_cb"); reset_timeout(); // Verify that we have a starting face if ( _orig_face ) { Bface* face = 0; // Check that the stroke is straight enough to represent a line if (!(gest->straightness() > 0.8)) { err_adv(debug, "INFLATE::stroke_cb: gesture not straight"); return false; } // Check that the gesture starts on the mesh Bsurface::hit_ctrl_surface(gest->start(), 1, &face); if (!(face)) { err_adv(debug, "INFLATE::stroke_cb: can't get hit face"); return false; } // create VEXELs for the gesture and the face normal VEXEL fvec = VEXEL(face->v1()->loc(), face->norm()); VEXEL fgest = gest->endpt_vec(); // If gesture nearly parallel to normal: double a = rad2deg(line_angle(fvec,fgest)); err_adv(debug, "INFLATE::stroke_cb: angle: %f %s", a, (a > 15) ? "(bad)" : "(good)"); if (a > 15) { // Fail if angle is too extreme WORLD::message("Bad angle"); return 0; } // calculate extrude width double dist = fgest.length()/fvec.length(); err_adv(debug, "INFLATE::stroke_cb: strong_edge_len: %f, gest_len: %f, \ fvect_len: %f", avg_strong_edge_len(face), fgest.length(), fvec.length() ); // Convert to relative to local edge length dist /= avg_strong_edge_len(face); if (fvec*fgest<0) dist=-dist; // Get the sign right // Store the new inflate distance _preview_dist = dist; } return 1; // we used up the gesture... }
int INFLATE::tap_cb(CGESTUREptr& gest, DrawState*& state) { err_adv(debug, "INFLATE::tap_cb"); // Tracks if the tap was near a guideline bool near_guidelines = false; PIXEL pdummy; int idummy; if ( PIXEL_list(_lines).closest( PIXEL(gest->start()), pdummy, idummy ) < 5 ) near_guidelines = true; // Check if gesture hits a BFace Bface* face = 0; Bsurface::hit_ctrl_surface(gest->start(), 1, &face); // Fail if Gesture missed guidelines and geometry if ( !face && !near_guidelines ) return cancel_cb(gest,state); // Check that we are trying to inflate if ( _orig_face ) { // Find the reachable faces from the starting point Bface_list set = _mode ? _faces : Bface_list::reachable_faces(_orig_face); // verify that the user tapped a face that is part of the inflation region if ( face && !set.contains( face ) ) { return cancel_cb(gest,state); } // Attempt to inflate the surface INFLATE_CMDptr cmd = _mode ? (new INFLATE_CMD( _faces, _preview_dist )) : (new INFLATE_CMD( _orig_face, _preview_dist )); WORLD::add_command(cmd); } // On fail, cancel return cancel_cb(gest,state); }
int INFLATE::line_cb(CGESTUREptr& gest, DrawState*& s) { // Activity occurred to extend the deadline for fading away: reset_timeout(); err_adv(debug, "INFLATE::line_cb"); // Verify that we have a starting face if ( _orig_face ) { // Check that the stroke is straight enough to represent a line Bface* face = 0; if (!(gest->straightness() > 0.8)) { err_adv(debug, "INFLATE::line_cb: gesture not straight"); return false; } // Check that the gesture starts on the mesh Bsurface::hit_ctrl_surface(gest->start(), 1, &face); if (!(face)) { err_adv(debug, "INFLATE::line_cb: can't get hit face"); return false; } // create VEXELs for the gesture and the face normal VEXEL fvec = VEXEL(face->v1()->loc(), face->norm()); VEXEL fgest = gest->endpt_vec(); // If gesture nearly parallel to normal: double a = rad2deg(line_angle(fvec,fgest)); err_adv(debug, "INFLATE::line_cb: angle: %f %s", a, (a > 15) ? "(bad)" : "(good)"); if (a > 15) { return false; } // calculate extrude width double dist = fgest.length()/fvec.length(); if (fvec*fgest<0) dist=-dist; // Get the sign right _preview_dist = dist; } // get here if nothing happened... // don't cancel (which would deactivate the widget), // just return 1 to indicate that we used up the gesture: return 1; }
int SWEEP_BASE::line_cb(CGESTUREptr& g, DrawState*& s) { // Activity occurred to extend the deadline for fading away: reset_timeout(); static bool debug = Config::get_var_bool("DEBUG_SWEEP_LINE_CB",false) || debug_all; err_adv(debug, "SWEEP_BASE::line_cb"); // If gesture aligns with guideline: // if it starts near the end and extends past the end, extend // if it starts near the beginning, do uniform sweep // If it's across the gesture, trim // If it's a trim stroke, it has to be short and run // across the guideline. const double TRIM_MAX_LEN = 65; if (g->length() < TRIM_MAX_LEN) { const double TRIM_ANGLE_THRESH = 80; // degrees double angle = line_angle(g->endpt_vec(), pix_line().direction()); if (rad2deg(angle) > TRIM_ANGLE_THRESH) { // Nice angle. But did it cross? if (g->endpt_line().intersect_segs(pix_line())) return trim_line_cb(g, s); } } // do uniform sweep if straight gesture starts at sweep origin // and ends near the guideline: if (from_center(g)) { if (hits_line(g->end())) return do_uniform_sweep(project_to_guideline(g->end()) - sweep_origin()); return stroke_cb(g,s); } // extend the guideline if straight gesture starts near guideline end // and is nearly parallel: const double ALIGN_ANGLE_THRESH = 15; // degrees if (pix_line().endpt().dist(g->start()) < DIST_THRESH_PIXELS && rad2deg(g->endpt_vec().angle(pix_line().direction())) < ALIGN_ANGLE_THRESH) return extend_line_cb(g, s); return stroke_cb(g,s); }
//! Given an initial slash gesture (or delayed slash) on a //! defined plane (FLOOR, Cursor3D, or existing Bpoint), set up //! the widget to provide a guideline for drawing a straight line. bool SWEEP_POINT::setup(CGESTUREptr& slash, double dur) { static bool debug = Config::get_var_bool("DEBUG_SWEEP_SETUP",false) || debug_all; err_adv(debug, "SWEEP_POINT::setup"); // check the gesture if (!(slash && slash->straightness() > 0.9)) { err_adv(debug, "SWEEP_POINT::setup: gesture is bad"); return false; } // find the (straight) Bpoint near slash start _point = Bpoint::hit_ctrl_point(slash->start()); return false; // return SWEEP_BASE::setup(_curve->mesh(), o, endpt, dur); }
bool SWEEP_BASE::from_center(CGESTUREptr& g) const { assert(g != nullptr); return g->start().dist(sweep_origin()) < DIST_THRESH_PIXELS; }
//! Given an initial slash gesture (or delayed slash) near the //! center of an existing straight Bcurve, set up the widget to //! do a sweep cross-ways to the Bcurve: bool SWEEP_LINE::setup(CGESTUREptr& slash, double dur) { static bool debug = Config::get_var_bool("DEBUG_SWEEP_SETUP",false) || debug_all; err_adv(debug, "SWEEP_LINE::setup"); // check the gesture if (!(slash && slash->straightness() > 0.99)) { err_adv(debug, "SWEEP_LINE::setup: gesture is bad"); return false; } // find the (straight) Bcurve near slash start _curve = Bcurve::hit_ctrl_curve(slash->start()); if (!(_curve && _curve->is_straight())) { err_adv(debug, "SWEEP_LINE::setup: no straight curve at start"); return false; } // find endpoints Bpoint *b1 = _curve->b1(), *b2 = _curve->b2(); assert(b1 && b2); // straight curve must have endpoints // curve cannot be connected to other curves if (b1->vert()->degree() != 1 || b2->vert()->degree() != 1) { err_adv(debug, "SWEEP_LINE::setup: curve is not isolated"); return false; } // ensure the gesture starts near the center of the straight line Bcurve: { PIXEL a = b1->vert()->pix(); PIXEL b = b2->vert()->pix(); double t = (slash->start() - a).tlen(b-a); if (t < 0.35 || t > 0.65) { err_adv(debug, "SWEEP_LINE::setup: gesture not near center of line"); return false; } } // find the plane to work in _plane = check_plane(shared_plane(b1, b2)); if (!_plane.is_valid()) { err_adv(debug, "SWEEP_LINE::setup: no valid plane"); return false; } // check that slash is perpendicular to line Wpt a = b1->loc(); // endpoint at b1 Wpt b = b2->loc(); // endpoint at b2 Wvec t = b - a; // vector from endpt a to endpt b Wpt o = a + t/2; // center of straight line curve Wvec n = cross(_plane.normal(), t); // direction across line ab Wvec slash_vec = endpt_vec(slash, _plane); const double ALIGN_ANGLE_THRESH = 15; double angle = rad2deg(slash_vec.angle(n)); if (angle > 90) { angle = 180 - angle; n = -n; } if (angle > ALIGN_ANGLE_THRESH) { err_adv(debug, "SWEEP_LINE::setup: slash is not perpendicular to line"); err_adv(debug, " angle: %f", angle); return false; } // compute guideline endpoint: Wpt endpt = o + n.normalized()*a.dist(b); return SWEEP_BASE::setup(_curve->mesh(), o, endpt, dur); }
inline Wvec endpt_vec(CGESTUREptr& g, CWplane& P) { return Wpt(P, Wline(g->end())) - Wpt(P, Wline(g->start())); }
int SELECT_WIDGET:: slash_cb(CGESTUREptr& gest, DrawState*& s) { if (_mode==SEL_FACE) //widget is in face selection mode { select_list.clear(); Bface* f = find_face(gest->start(),0.25,MIN_PIX_AREA); // f should be the currently selected face if (f && f->is_selected() && f->is_quad()) { f=f->quad_rep(); //line in screen space coresponding to the slash PIXELline slash(gest->start(),gest->end()); Bedge *e1,*e2,*e3,*e4; Bedge* edge = 0; //get and test the quad edges against the stroke line f->get_quad_edges(e1,e2,e3,e4); if( e1->pix_line().intersect_segs(slash) ) { edge=e1; } else if( e2->pix_line().intersect_segs(slash) ) { edge=e2; } else if( e3->pix_line().intersect_segs(slash) ) { edge=e3; } else if( e4->pix_line().intersect_segs(slash) ) { edge=e4; } else { //error cerr << "ERROR no intersection" << endl; return 1; } //walk the geometry and select faces Bface* fn = f; do { if (!fn->is_selected()) select_list +=fn; assert(edge); //I'm paranoid too assert(edge->f1()!=edge->f2()); //grabs the face on the other side of the edge //even if we are not directly adjacent to this edge fn=fn->other_quad_face(edge); if (fn) //if a valid face than advance the edge pointer { assert(edge!=fn->opposite_quad_edge(edge)); edge = fn->opposite_quad_edge(edge); fn = fn->quad_rep(); //all faces on the selection list are rep faces } else cerr << "No face on the other side of the edge" << endl; } //quit if not a valid face or not a quad while(fn&&(fn->is_quad())&&edge&&(fn!=f)); _mode=SLASH_SEL; //go into pattern editing mode end_face=0; //prepare the 2nd step data pattern=0; for (int i=0; i<MAX_PATTERN_SIZE; i++) pattern_array[i]=1; //fill the default pattern with ones } else cerr << "This is not a quad" << endl; } else if( _mode==SLASH_SEL)//pattern editing mode { //activates upon second slash motion //adds the entire list to the selected group //undo deselects the entire group Bface_list final_list; //copy the face pointers to the final list //using the pattern as a repeating template //and stop at the end face for (int i = 0; i<(end_face ? (end_face) : select_list.num()) ; i++) { if (pattern ? pattern_array[(i%pattern)+1] : 1) final_list+=select_list[i]; } WORLD::add_command(new MESH_SELECT_CMD(final_list)); return cancel_cb(gest,s); } else cerr << "wrong mode " << endl; return 1; }