"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/Edit/Interface/edit_graphics.cpp" between
TeXmacs-1.99.4-src.tar.gz and TeXmacs-1.99.5-src.tar.gz

About: GNU TeXmacs is a what-you-see-is-what-you-get scientific text editor, which was both inspired by TeX and GNU Emacs.

edit_graphics.cpp  (TeXmacs-1.99.4-src):edit_graphics.cpp  (TeXmacs-1.99.5-src)
skipping to change at line 27 skipping to change at line 27
#include "Bridge/impl_typesetter.hpp" #include "Bridge/impl_typesetter.hpp"
#include "drd_std.hpp" #include "drd_std.hpp"
extern tree the_et; extern tree the_et;
/****************************************************************************** /******************************************************************************
* Constructors and destructors * Constructors and destructors
******************************************************************************/ ******************************************************************************/
edit_graphics_rep::edit_graphics_rep () { edit_graphics_rep::edit_graphics_rep () {
p_x= p_y= 0.0;
gr_x= gr_y= 0.0; gr_x= gr_y= 0.0;
graphical_object= tree(); graphical_object= tree();
} }
edit_graphics_rep::~edit_graphics_rep () {} edit_graphics_rep::~edit_graphics_rep () {}
/****************************************************************************** /******************************************************************************
* Extra subroutines for graphical selections * Extra subroutines for graphical selections
******************************************************************************/ ******************************************************************************/
static tree snap_mode;
static SI snap_distance;
void
set_snap_mode (tree t) {
//cout << "Snap mode= " << t << "\n";
snap_mode= t;
}
void
set_snap_distance (SI d) {
//cout << "Snap distance= " << d << "\n";
snap_distance= d;
}
bool
check_snap_mode (string type) {
if (!is_tuple (snap_mode)) return true;
for (int i=0; i<N(snap_mode); i++)
if (snap_mode[i] == "all") return true;
else if (snap_mode[i] == type) return true;
return false;
}
bool
can_snap (gr_selection sel) {
string type= sel->type;
if (type == "free")
return true;
if (type == "box")
return false;
if (type == "point")
return check_snap_mode ("control point");
if (type == "curve-handle")
return check_snap_mode ("control point");
if (type == "curve-point")
return check_snap_mode ("curve point");
if (type == "curve-point&curve-point")
return check_snap_mode ("curve-curve intersection");
if (type == "grid-point")
return check_snap_mode ("grid point");
if (type == "grid-curve-point")
return check_snap_mode ("grid curve point");
if (type == "curve-point&grid-curve-point")
return check_snap_mode ("curve-grid intersection");
if (type == "grid-curve-point&curve-point")
return check_snap_mode ("curve-grid intersection");
if (type == "text" || type == "group")
return check_snap_mode ("text");
if (type == "text-handle")
return check_snap_mode ("control point");
if (type == "text-border")
return check_snap_mode ("text border");
if (type == "text-border-point")
return check_snap_mode ("text border point");
if (type == "text-border&grid-curve-point")
return check_snap_mode ("text border") &&
check_snap_mode ("curve-curve intersection");
if (type == "grid-curve-point&text-border")
return check_snap_mode ("text border") &&
check_snap_mode ("curve-curve intersection");
cout << "Uncaptured snap type " << type << "\n";
return true;
}
gr_selection gr_selection
snap_to_guide (point p, gr_selections sels, double eps) { snap_to_guide (point p, gr_selections sels, double eps) {
if (N(sels) == 0) { if (N(sels) == 0) {
gr_selection snap; gr_selection snap;
snap->type= "free"; snap->type= "free";
snap->p= p; snap->p= p;
snap->dist= 0; snap->dist= 0;
return snap; return snap;
} }
sort (sels); sort (sels);
gr_selection best; gr_selection best;
best->type= "none"; best->type= "none";
for (int i=0; i<N(sels); i++) for (int i=0; i<N(sels); i++)
if (sels[i]->type == "grid-point") if (can_snap (sels[i])) {
best= sels[i]; if (sels[i]->type == "grid-point")
else if (is_nil (sels[i]->c)) best= sels[i];
return sels[i]; else if (is_nil (sels[i]->c))
return sels[i];
}
for (int i=0; i<N(sels); i++) for (int i=0; i<N(sels); i++)
for (int j=i+1; j<N(sels); j++) { for (int j=i+1; j<N(sels); j++) {
if (!is_nil (sels[i]->c) && if (!is_nil (sels[i]->c) &&
!is_nil (sels[j]->c) && !is_nil (sels[j]->c) &&
(sels[i]->type != "grid-curve-point" || (sels[i]->type != "grid-curve-point" ||
sels[j]->type != "grid-curve-point")) sels[j]->type != "grid-curve-point") &&
!ends (sels[i]->type, "handle") &&
!ends (sels[j]->type, "handle"))
{ {
array<point> ins= intersection (sels[i]->c, sels[j]->c, p, eps); array<point> ins= intersection (sels[i]->c, sels[j]->c, p, eps);
for (int k=0; k<N(ins); k++) for (int k=0; k<N(ins); k++)
if (best->type == "none" || norm (ins[k] - p) < best->dist) { if (best->type == "none" || norm (ins[k] - p) < best->dist) {
gr_selection sel; gr_selection sel;
sel->type= sels[i]->type * "&" * sels[j]->type; sel->type= sels[i]->type * "&" * sels[j]->type;
sel->p = ins[k]; sel->p = ins[k];
sel->dist= (SI) norm (ins[k] - p); sel->dist= (SI) norm (ins[k] - p);
sel->cp = append (sels[i]->cp, sels[j]->cp); sel->cp = append (sels[i]->cp, sels[j]->cp);
sel->pts = append (sels[i]->pts, sels[j]->pts); sel->pts = append (sels[i]->pts, sels[j]->pts);
best= sel; if (can_snap (sel)) best= sel;
} }
} }
} }
if (best->type != "none") return best; if (best->type != "none") return best;
return sels[0]; if (can_snap (sels[0])) return sels[0];
else {
gr_selection snap;
snap->type= "free";
snap->p= p;
snap->dist= 0;
return snap;
}
} }
/****************************************************************************** /******************************************************************************
* Main edit_graphics routines * Main edit_graphics routines
******************************************************************************/ ******************************************************************************/
path path
edit_graphics_rep::graphics_path () { edit_graphics_rep::graphics_path () {
path gp= search_upwards (GRAPHICS); path gp= search_upwards (GRAPHICS);
if (is_nil (gp)) return tp; if (is_nil (gp)) return tp;
skipping to change at line 176 skipping to change at line 253
else return grid (); else return grid ();
} }
void void
edit_graphics_rep::find_limits (point& lim1, point& lim2) { edit_graphics_rep::find_limits (point& lim1, point& lim2) {
path gp= graphics_path (); path gp= graphics_path ();
lim1= point (); lim2= point (); lim1= point (); lim2= point ();
bool bp_found; bool bp_found;
path bp= eb->find_box_path (gp, bp_found); path bp= eb->find_box_path (gp, bp_found);
if (bp_found) eb->find_limits (path_up (bp), lim1, lim2); if (bp_found) eb->find_limits (path_up (bp), lim1, lim2);
if (N(lim1) >= 2 && fabs (lim1[0]) <= 0.001) lim1[0]= 0.0;
if (N(lim1) >= 2 && fabs (lim1[1]) <= 0.001) lim1[1]= 0.0;
if (N(lim2) >= 2 && fabs (lim2[0]) <= 0.001) lim2[0]= 0.0;
if (N(lim2) >= 2 && fabs (lim2[1]) <= 0.001) lim2[1]= 0.0;
} }
bool bool
edit_graphics_rep::find_graphical_region (SI& x1, SI& y1, SI& x2, SI& y2) { edit_graphics_rep::find_graphical_region (SI& x1, SI& y1, SI& x2, SI& y2) {
point lim1, lim2; point lim1, lim2;
find_limits (lim1, lim2); find_limits (lim1, lim2);
if (lim1 == point ()) return false; if (lim1 == point ()) return false;
frame f= find_frame (); frame f= find_frame ();
if (is_nil (f)) return false; if (is_nil (f)) return false;
point p1= f (point (lim1[0], lim1[1])); point p1= f (point (lim1[0], lim1[1]));
point p2= f (point (lim2[0], lim2[1])); point p2= f (point (lim2[0], lim2[1]));
x1= (SI) p1[0]; y1= (SI) p1[1]; x1= (SI) p1[0]; y1= (SI) p1[1];
x2= (SI) p2[0]; y2= (SI) p2[1]; x2= (SI) p2[0]; y2= (SI) p2[1];
return true; return true;
} }
point point
edit_graphics_rep::adjust (point p) { edit_graphics_rep::adjust (point p) {
frame f= find_frame (); frame f= find_frame ();
grid g= find_grid (); grid g= find_grid ();
if (!is_nil (g) && !is_nil (gr0) && g != gr0) { if (!is_nil (g) && !is_nil (gr0) &&
(g != gr0 || p[0] != p_x || p[1] != p_y)) {
graphical_select (p[0], p[1]); graphical_select (p[0], p[1]);
g= gr0; g= gr0;
p[0]= p_x;
p[1]= p_y;
} }
if (is_nil (g)) return p; if (is_nil (g)) return p;
point res; point res;
gr_selections sels= copy (gs); gr_selections sels= copy (gs);
frame f2= find_frame (true); frame f2= find_frame (true);
if (is_nil (f2)) return p; if (is_nil (f2)) return p;
point fp= f2 (p); point fp= f2 (p);
if ((tree) g != "empty_grid") { if ((tree) g != "empty_grid") {
point q= g->find_point_around (p, 10*get_pixel_size (), f); point q= g->find_point_around (p, snap_distance, f);
point fq= f2 (q); point fq= f2 (q);
if (norm (fq - fp) < 10*get_pixel_size ()) { if (norm (fq - fp) < snap_distance) {
gr_selection sel; gr_selection sel;
sel->type= "grid-point"; sel->type= "grid-point";
sel->p = fq; sel->p = fq;
sel->dist= (SI) norm (fq - fp); sel->dist= (SI) norm (fq - fp);
sels << sel; sels << sel;
} }
array<grid_curve> gc= array<grid_curve> gc=
g->get_curves_around (p, 10*get_pixel_size (), f); g->get_curves_around (p, snap_distance, f);
for (int i=0; i<N(gc); i++) { for (int i=0; i<N(gc); i++) {
point fc= closest (f2 (gc[i]->c), fp); point fc= closest (f2 (gc[i]->c), fp);
if (norm (fc - fp) < 10*get_pixel_size ()) { if (norm (fc - fp) < snap_distance) {
gr_selection sel; gr_selection sel;
sel->type= "grid-curve-point"; sel->type= "grid-curve-point";
sel->p = fc; sel->p = fc;
sel->dist= (SI) norm (fc - fp); sel->dist= (SI) norm (fc - fp);
sel->c = f2 (gc[i]->c); sel->c = f2 (gc[i]->c);
sels << sel; sels << sel;
} }
} }
} }
double eps= get_pixel_size () / 10.0; double eps= get_pixel_size () / 10.0;
skipping to change at line 244 skipping to change at line 328
if (N(snapped) == 2) return snapped; if (N(snapped) == 2) return snapped;
return p; return p;
// FIXME: why can snapped be an invalid point? // FIXME: why can snapped be an invalid point?
} }
tree tree
edit_graphics_rep::find_point (point p) { edit_graphics_rep::find_point (point p) {
return tree (_POINT, as_string (p[0]), as_string (p[1])); return tree (_POINT, as_string (p[0]), as_string (p[1]));
} }
bool
admissible_selection (gr_selection sel) {
if (sel->type != "box" || N(sel->cp) != 1) return true;
if (last_item (sel->cp[0]) < 0 || N(sel->cp[0]) <= 2) return true;
path p= path_up (sel->cp[0]);
if (!has_subtree (the_et, p)) return true;
tree st= subtree (the_et, p);
if (is_compound (st, "anim-edit")) return false;
tree pt= subtree (the_et, path_up (p));
if (is_func (st, WITH) && is_compound (pt, "anim-edit")) return false;
return true;
}
tree tree
edit_graphics_rep::graphical_select (double x, double y) { edit_graphics_rep::graphical_select (double x, double y) {
frame f= find_frame (); frame f= find_frame ();
if (is_nil (f)) return tuple (); if (is_nil (f)) return tuple ();
gr_selections sels; gr_selections pre_sels, sels;
point p0 = point (x, y); point p0 = point (x, y);
point p = f (p0); point p = f (p0);
sels= eb->graphical_select ((SI)p[0], (SI)p[1], 10*get_pixel_size ()); pre_sels= eb->graphical_select ((SI)p[0], (SI)p[1], snap_distance);
for (int i=0; i<N(pre_sels); i++)
if (admissible_selection (pre_sels[i]))
sels << pre_sels[i];
//for (int i=0; i<N(sels); i++)
// cout << i << ":\t" << sels[i] << "\n";
gs= sels; gs= sels;
gr0= empty_grid (); gr0= empty_grid ();
grid g= find_grid (); grid g= find_grid ();
frame f2= find_frame (true); frame f2= find_frame (true);
if (!is_nil (g) && !is_nil (f2)) gr0= g; if (!is_nil (g) && !is_nil (f2)) {
gr0= g;
p_x= x;
p_y= y;
}
return as_tree (sels); return as_tree (sels);
} }
tree tree
edit_graphics_rep::graphical_select ( edit_graphics_rep::graphical_select (
double x1, double y1, double x2, double y2) double x1, double y1, double x2, double y2)
{ {
frame f= find_frame (); frame f= find_frame ();
if (is_nil (f)) return tuple (); if (is_nil (f)) return tuple ();
gr_selections sels; gr_selections sels;
skipping to change at line 349 skipping to change at line 455
else { else {
rectangles rs; rectangles rs;
b->redraw (ren, path (), rs); b->redraw (ren, path (), rs);
} }
} }
ren->set_clipping (ox1, oy1, ox2, oy2); ren->set_clipping (ox1, oy1, ox2, oy2);
} }
void void
edit_graphics_rep::back_in_text_at (tree t, path p, bool forward) { edit_graphics_rep::back_in_text_at (tree t, path p, bool forward) {
(void) forward;
int i= last_item (p); int i= last_item (p);
if ((i == 0) && is_empty (t[0])) { if ((i == 0) && is_empty (t[0])) {
p= path_up (p); p= path_up (p);
if (is_func (subtree (et, path_up (p)), WITH)) p= path_up (p); if (is_func (subtree (et, path_up (p)), WITH)) p= path_up (p);
tree st= subtree (et, path_up (p)); tree st= subtree (et, path_up (p));
if (is_func (st, GRAPHICS)) { if (is_func (st, GRAPHICS)) {
if (N(st) == 1) assign (p, ""); if (N(st) == 1) assign (p, "");
else { else {
remove (p, 1); remove (p, 1);
go_to_border (path_up (p) * 0, true); go_to_border (path_up (p) * 0, true);
 End of changes. 18 change blocks. 
15 lines changed or deleted 122 lines changed or added

Home  |  About  |  All  |  Newest  |  Fossies Dox  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTPS