Lines Matching defs:box

43 static void box3d_ref_changed(SPObject *old_ref, SPObject *ref, SPBox3D *box);
86 SPBox3D *box = object;
88 if (box->persp_href) {
89 g_free(box->persp_href);
95 Persp3D *persp = box3d_get_perspective(box);
97 if (box->persp_ref) {
98 box->persp_ref->detach();
99 delete box->persp_ref;
100 box->persp_ref = NULL;
104 persp3d_remove_box (persp, box);
106 // TODO: This deletes a perspective when the last box referring to it is gone. Eventually,
107 // it would be nice to have this but currently it crashes when undoing/redoing box deletion
108 // Reason: When redoing a box deletion, the associated perspective is deleted twice, first
112 SPDocument *doc = box->document;
124 SPBox3D *box = object;
128 if ( value && box->persp_href && ( strcmp(value, box->persp_href) == 0 ) ) {
131 if (box->persp_href) {
132 g_free(box->persp_href);
133 box->persp_href = NULL;
136 box->persp_href = g_strdup(value);
140 box->persp_ref->attach(Inkscape::URI(value));
143 box->persp_ref->detach();
147 box->persp_ref->detach();
152 box3d_position_set(box);
156 box->orig_corner0 = Proj::Pt3(value);
157 box->save_corner0 = box->orig_corner0;
158 box3d_position_set(box);
163 box->orig_corner7 = Proj::Pt3(value);
164 box->save_corner7 = box->orig_corner7;
165 box3d_position_set(box);
178 box3d_ref_changed(SPObject *old_ref, SPObject *ref, SPBox3D *box)
181 sp_signal_disconnect_by_data(old_ref, box);
184 persp3d_remove_box(oldPersp, box);
188 if ( persp && (ref != box) ) // FIXME: Comparisons sane?
190 persp3d_add_box(persp, box);
197 /* FIXME?: Perhaps the display updates of box sides should be instantiated from here, but this
209 SPBox3D *box = object;
213 // thus we don' set "sodipodi:type" so that the box is only saved as an ordinary svg:g
219 if (box->persp_href) {
220 repr->setAttribute("inkscape:perspectiveID", box->persp_href);
222 /* box is not yet linked to a perspective; use the document's current perspective */
224 if (box->persp_ref->getURI()) {
225 gchar *uri_string = box->persp_ref->getURI()->toString();
235 gchar *coordstr0 = box->orig_corner0.coord_string();
236 gchar *coordstr7 = box->orig_corner7.coord_string();
242 box->orig_corner0.normalize();
243 box->orig_corner7.normalize();
245 box->save_corner0 = box->orig_corner0;
246 box->save_corner7 = box->orig_corner7;
258 void box3d_position_set(SPBox3D *box)
261 box3d_side_position_set() to avoid update conflicts with the parent box) */
262 for ( SPObject *obj = box->firstChild(); obj; obj = obj->getNext() ) {
271 // We don't apply the transform to the box directly but instead to its perspective (which is
307 box3d_get_proj_corner (SPBox3D const *box, guint id) {
308 return Proj::Pt3 ((id & Box3D::X) ? box->orig_corner7[Proj::X] : box->orig_corner0[Proj::X],
309 (id & Box3D::Y) ? box->orig_corner7[Proj::Y] : box->orig_corner0[Proj::Y],
310 (id & Box3D::Z) ? box->orig_corner7[Proj::Z] : box->orig_corner0[Proj::Z],
315 box3d_get_corner_screen (SPBox3D const *box, guint id, bool item_coords) {
316 Proj::Pt3 proj_corner (box3d_get_proj_corner (box, id));
317 if (!box3d_get_perspective(box)) {
320 Geom::Affine const i2d(box->i2dt_affine ());
322 return box3d_get_perspective(box)->perspective_impl->tmat.image(proj_corner).affine() * i2d.inverse();
324 return box3d_get_perspective(box)->perspective_impl->tmat.image(proj_corner).affine();
329 box3d_get_proj_center (SPBox3D *box) {
330 box->orig_corner0.normalize();
331 box->orig_corner7.normalize();
332 return Proj::Pt3 ((box->orig_corner0[Proj::X] + box->orig_corner7[Proj::X]) / 2,
333 (box->orig_corner0[Proj::Y] + box->orig_corner7[Proj::Y]) / 2,
334 (box->orig_corner0[Proj::Z] + box->orig_corner7[Proj::Z]) / 2,
339 box3d_get_center_screen (SPBox3D *box) {
340 Proj::Pt3 proj_center (box3d_get_proj_center (box));
341 if (!box3d_get_perspective(box)) {
344 Geom::Affine const i2d( box->i2dt_affine() );
345 return box3d_get_perspective(box)->perspective_impl->tmat.image(proj_center).affine() * i2d.inverse();
362 box3d_snap (SPBox3D *box, int id, Proj::Pt3 const &pt_proj, Proj::Pt3 const &start_pt) {
364 double diff_x = box->save_corner7[Proj::X] - box->save_corner0[Proj::X];
365 double diff_y = box->save_corner7[Proj::Y] - box->save_corner0[Proj::Y];
374 Persp3DImpl *persp_impl = box3d_get_perspective(box)->perspective_impl;
383 // (this might help to prevent rounding errors if the box is small)
436 return box3d_get_perspective(box)->perspective_impl->tmat.preimage (result, z_coord, Proj::Z);
450 box3d_set_corner (SPBox3D *box, const guint id, Geom::Point const &new_pos, const Box3D::Axis movement, bool constrained) {
453 box->orig_corner0.normalize();
454 box->orig_corner7.normalize();
458 Persp3DImpl *persp_impl = box3d_get_perspective(box)->perspective_impl;
459 Proj::Pt3 pt_proj (persp_impl->tmat.preimage (new_pos, (id < 4) ? box->orig_corner0[Proj::Z] :
460 box->orig_corner7[Proj::Z], Proj::Z));
462 pt_proj = box3d_snap (box, id, pt_proj, box3d_get_proj_corner (id, box->save_corner0, box->save_corner7));
467 box->orig_corner0 = Proj::Pt3 ((id & Box3D::X) ? box->save_corner0[Proj::X] : pt_proj[Proj::X],
468 (id & Box3D::Y) ? box->save_corner0[Proj::Y] : pt_proj[Proj::Y],
469 box->save_corner0[Proj::Z],
471 box->orig_corner7 = Proj::Pt3 ((id & Box3D::X) ? pt_proj[Proj::X] : box->save_corner7[Proj::X],
472 (id & Box3D::Y) ? pt_proj[Proj::Y] : box->save_corner7[Proj::Y],
473 box->save_corner7[Proj::Z],
476 Persp3D *persp = box3d_get_perspective(box);
477 Persp3DImpl *persp_impl = box3d_get_perspective(box)->perspective_impl;
479 box3d_get_proj_corner (id, box->save_corner0, box->save_corner7)).affine(),
483 box3d_get_proj_corner (box, id)[(movement & Box3D::Y) ? Proj::X : Proj::Y],
491 box->orig_corner0 = Proj::Pt3 (corner0_move_x ? pt_proj[Proj::X] : box->orig_corner0[Proj::X],
492 corner0_move_y ? pt_proj[Proj::Y] : box->orig_corner0[Proj::Y],
493 (id & Box3D::Z) ? box->orig_corner0[Proj::Z] : pt_proj[Proj::Z],
495 box->orig_corner7 = Proj::Pt3 (corner7_move_x ? pt_proj[Proj::X] : box->orig_corner7[Proj::X],
496 corner7_move_y ? pt_proj[Proj::Y] : box->orig_corner7[Proj::Y],
497 (id & Box3D::Z) ? pt_proj[Proj::Z] : box->orig_corner7[Proj::Z],
500 // FIXME: Should we update the box here? If so, how?
503 void box3d_set_center (SPBox3D *box, Geom::Point const &new_pos, Geom::Point const &old_pos, const Box3D::Axis movement, bool constrained) {
506 box->orig_corner0.normalize();
507 box->orig_corner7.normalize();
509 Persp3D *persp = box3d_get_perspective(box);
511 double coord = (box->orig_corner0[Proj::Z] + box->orig_corner7[Proj::Z]) / 2;
512 double radx = (box->orig_corner7[Proj::X] - box->orig_corner0[Proj::X]) / 2;
513 double rady = (box->orig_corner7[Proj::Y] - box->orig_corner0[Proj::Y]) / 2;
519 pt_proj = box3d_snap (box, -1, pt_proj, old_pos_proj);
523 box->orig_corner0 = Proj::Pt3 ((movement & Box3D::X) ? pt_proj[Proj::X] - radx : box->orig_corner0[Proj::X],
524 (movement & Box3D::Y) ? pt_proj[Proj::Y] - rady : box->orig_corner0[Proj::Y],
525 box->orig_corner0[Proj::Z],
527 box->orig_corner7 = Proj::Pt3 ((movement & Box3D::X) ? pt_proj[Proj::X] + radx : box->orig_corner7[Proj::X],
528 (movement & Box3D::Y) ? pt_proj[Proj::Y] + rady : box->orig_corner7[Proj::Y],
529 box->orig_corner7[Proj::Z],
532 double coord = (box->orig_corner0[Proj::X] + box->orig_corner7[Proj::X]) / 2;
533 double radz = (box->orig_corner7[Proj::Z] - box->orig_corner0[Proj::Z]) / 2;
541 box->orig_corner0 = Proj::Pt3 (box->orig_corner0[Proj::X],
542 box->orig_corner0[Proj::Y],
545 box->orig_corner7 = Proj::Pt3 (box->orig_corner7[Proj::X],
546 box->orig_corner7[Proj::Y],
556 void box3d_corners_for_PLs (const SPBox3D * box, Proj::Axis axis,
559 Persp3D *persp = box3d_get_perspective(box);
562 //box->orig_corner0.normalize();
563 //box->orig_corner7.normalize();
564 double coord = (box->orig_corner0[axis] > box->orig_corner7[axis]) ?
565 box->orig_corner0[axis] :
566 box->orig_corner7[axis];
572 c1 = Proj::Pt3 (coord, box->orig_corner0[Proj::Y], box->orig_corner0[Proj::Z], 1.0);
573 c2 = Proj::Pt3 (coord, box->orig_corner7[Proj::Y], box->orig_corner0[Proj::Z], 1.0);
574 c3 = Proj::Pt3 (coord, box->orig_corner7[Proj::Y], box->orig_corner7[Proj::Z], 1.0);
575 c4 = Proj::Pt3 (coord, box->orig_corner0[Proj::Y], box->orig_corner7[Proj::Z], 1.0);
578 c1 = Proj::Pt3 (box->orig_corner0[Proj::X], coord, box->orig_corner0[Proj::Z], 1.0);
579 c2 = Proj::Pt3 (box->orig_corner7[Proj::X], coord, box->orig_corner0[Proj::Z], 1.0);
580 c3 = Proj::Pt3 (box->orig_corner7[Proj::X], coord, box->orig_corner7[Proj::Z], 1.0);
581 c4 = Proj::Pt3 (box->orig_corner0[Proj::X], coord, box->orig_corner7[Proj::Z], 1.0);
584 c1 = Proj::Pt3 (box->orig_corner7[Proj::X], box->orig_corner7[Proj::Y], coord, 1.0);
585 c2 = Proj::Pt3 (box->orig_corner7[Proj::X], box->orig_corner0[Proj::Y], coord, 1.0);
586 c3 = Proj::Pt3 (box->orig_corner0[Proj::X], box->orig_corner0[Proj::Y], coord, 1.0);
587 c4 = Proj::Pt3 (box->orig_corner0[Proj::X], box->orig_corner7[Proj::Y], coord, 1.0);
645 box3d_XY_axes_are_swapped (SPBox3D *box) {
646 Persp3D *persp = box3d_get_perspective(box);
648 Box3D::PerspectiveLine l1(box3d_get_corner_screen(box, 3, false), Proj::X, persp);
649 Box3D::PerspectiveLine l2(box3d_get_corner_screen(box, 3, false), Proj::Y, persp);
681 box3d_set_new_z_orders_case0 (SPBox3D *box, int z_orders[6], Box3D::Axis central_axis) {
682 bool swapped = box3d_XY_axes_are_swapped(box);
721 box3d_set_new_z_orders_case1 (SPBox3D *box, int z_orders[6], Box3D::Axis central_axis, Box3D::Axis fin_axis) {
722 Persp3D *persp = box3d_get_perspective(box);
730 inside1 = box3d_pt_lies_in_PL_sector (box, vp, 3, 3 ^ oaxis2, oaxis1);
731 inside2 = box3d_pt_lies_in_PL_sector (box, vp, 3, 3 ^ oaxis1, oaxis2);
733 bool swapped = box3d_XY_axes_are_swapped(box);
792 box3d_set_new_z_orders_case2 (SPBox3D *box, int z_orders[6], Box3D::Axis central_axis, Box3D::Axis /*infinite_axis*/) {
793 Geom::Point c3(box3d_get_corner_screen(box, 3, false));
795 bool swapped = box3d_XY_axes_are_swapped(box);
797 int insidexy = box3d_VP_lies_in_PL_sector (box, Proj::X, 3, 3 ^ Box3D::Z, Box3D::Y);
798 //int insidexz = box3d_VP_lies_in_PL_sector (box, Proj::X, 3, 3 ^ Box3D::Y, Box3D::Z);
800 int insideyx = box3d_VP_lies_in_PL_sector (box, Proj::Y, 3, 3 ^ Box3D::Z, Box3D::X);
801 int insideyz = box3d_VP_lies_in_PL_sector (box, Proj::Y, 3, 3 ^ Box3D::X, Box3D::Z);
803 //int insidezx = box3d_VP_lies_in_PL_sector (box, Proj::Z, 3, 3 ^ Box3D::Y, Box3D::X);
804 int insidezy = box3d_VP_lies_in_PL_sector (box, Proj::Z, 3, 3 ^ Box3D::X, Box3D::Y);
874 * It can happen that during dragging the box is everted.
878 box3d_everted_directions (SPBox3D *box) {
881 box->orig_corner0.normalize();
882 box->orig_corner7.normalize();
884 if (box->orig_corner0[Proj::X] < box->orig_corner7[Proj::X])
886 if (box->orig_corner0[Proj::Y] < box->orig_corner7[Proj::Y])
888 if (box->orig_corner0[Proj::Z] > box->orig_corner7[Proj::Z]) // FIXME: Remove the need to distinguish signs among the cases
919 box3d_recompute_z_orders (SPBox3D *box) {
920 Persp3D *persp = box3d_get_perspective(box);
927 Geom::Point c3(box3d_get_corner_screen(box, 3, false));
958 box3d_set_new_z_orders_case0(box, z_orders, central_axis);
961 box3d_set_new_z_orders_case1(box, z_orders, central_axis, axis_finite);
965 box3d_set_new_z_orders_case2(box, z_orders, central_axis, axis_infinite);
982 Geom::Point c3 = box3d_get_corner_screen(box, 3, false);
999 if (box3d_XY_axes_are_swapped(box)) {
1004 Geom::Point c1(box3d_get_corner_screen(box, 1, false));
1005 Geom::Point c2(box3d_get_corner_screen(box, 2, false));
1006 Geom::Point c7(box3d_get_corner_screen(box, 7, false));
1055 Box3D::Axis ev = box3d_everted_directions(box);
1064 if (box->z_orders[i] != z_orders[i]) {
1066 box->z_orders[j] = z_orders[j];
1074 static std::map<int, Box3DSide *> box3d_get_sides(SPBox3D *box)
1077 for ( SPObject *obj = box->firstChild(); obj; obj = obj->getNext() ) {
1088 // TODO: Check whether the box is everted in any direction and swap the sides opposite to this direction
1090 box3d_set_z_orders (SPBox3D *box) {
1092 if (box3d_recompute_z_orders (box)) {
1093 std::map<int, Box3DSide *> sides = box3d_get_sides(box);
1096 side = sides.find(box->z_orders[i]);
1117 box3d_pt_lies_in_PL_sector (SPBox3D const *box, Geom::Point const &pt, int id1, int id2, Box3D::Axis axis) {
1118 Persp3D *persp = box3d_get_perspective(box);
1121 Geom::Point c1(box3d_get_corner_screen(box, id1, false));
1122 Geom::Point c2(box3d_get_corner_screen(box, id2, false));
1137 Geom::Point c3(box3d_get_corner_screen(box, id1 ^ axis, false));
1149 box3d_VP_lies_in_PL_sector (SPBox3D const *box, Proj::Axis vpdir, int id1, int id2, Box3D::Axis axis) {
1150 Persp3D *persp = box3d_get_perspective(box);
1155 return box3d_pt_lies_in_PL_sector(box, persp3d_get_VP(persp, vpdir).affine(), id1, id2, axis);
1161 box3d_swap_coords(SPBox3D *box, Proj::Axis axis, bool smaller = true) {
1162 box->orig_corner0.normalize();
1163 box->orig_corner7.normalize();
1164 if ((box->orig_corner0[axis] < box->orig_corner7[axis]) != smaller) {
1165 double tmp = box->orig_corner0[axis];
1166 box->orig_corner0[axis] = box->orig_corner7[axis];
1167 box->orig_corner7[axis] = tmp;
1174 box3d_relabel_corners(SPBox3D *box) {
1175 box3d_swap_coords(box, Proj::X, false);
1176 box3d_swap_coords(box, Proj::Y, false);
1177 box3d_swap_coords(box, Proj::Z, true);
1181 box3d_check_for_swapped_coords(SPBox3D *box, Proj::Axis axis, bool smaller) {
1182 box->orig_corner0.normalize();
1183 box->orig_corner7.normalize();
1185 if ((box->orig_corner0[axis] < box->orig_corner7[axis]) != smaller) {
1186 box->swapped = (Box3D::Axis) (box->swapped | Proj::toAffine(axis));
1188 box->swapped = (Box3D::Axis) (box->swapped & ~Proj::toAffine(axis));
1193 box3d_exchange_coords(SPBox3D *box) {
1194 box->orig_corner0.normalize();
1195 box->orig_corner7.normalize();
1198 if (box->swapped & Box3D::axes[i]) {
1199 double tmp = box->orig_corner0[i];
1200 box->orig_corner0[i] = box->orig_corner7[i];
1201 box->orig_corner7[i] = tmp;
1207 box3d_check_for_swapped_coords(SPBox3D *box) {
1208 box3d_check_for_swapped_coords(box, Proj::X, false);
1209 box3d_check_for_swapped_coords(box, Proj::Y, false);
1210 box3d_check_for_swapped_coords(box, Proj::Z, true);
1212 box3d_exchange_coords(box);
1216 SPBox3D *box = dynamic_cast<SPBox3D *>(obj);
1217 if (box) {
1218 boxes.push_back(box);
1234 box3d_get_perspective(SPBox3D const *box) {
1235 return box->persp_ref->getObject();
1239 box3d_switch_perspectives(SPBox3D *box, Persp3D *old_persp, Persp3D *new_persp, bool recompute_corners) {
1241 box->orig_corner0.normalize();
1242 box->orig_corner7.normalize();
1243 double z0 = box->orig_corner0[Proj::Z];
1244 double z7 = box->orig_corner7[Proj::Z];
1245 Geom::Point corner0_screen = box3d_get_corner_screen(box, 0, false);
1246 Geom::Point corner7_screen = box3d_get_corner_screen(box, 7, false);
1248 box->orig_corner0 = new_persp->perspective_impl->tmat.preimage(corner0_screen, z0, Proj::Z);
1249 box->orig_corner7 = new_persp->perspective_impl->tmat.preimage(corner7_screen, z7, Proj::Z);
1252 persp3d_remove_box (old_persp, box);
1253 persp3d_add_box (new_persp, box);
1257 box->setAttribute("inkscape:perspectiveID", href.c_str());
1260 /* Converts the 3D box to an ordinary SPGroup, adds it to the XML tree at the same position as
1261 the original box and deletes the latter */
1262 SPGroup *box3d_convert_to_group(SPBox3D *box)
1264 SPDocument *doc = box->document;
1267 // remember position of the box
1268 int pos = box->getPosition();
1271 gchar const *id = box->getAttribute("id");
1272 gchar const *style = box->getAttribute("style");
1273 gchar const *mask = box->getAttribute("mask");
1274 gchar const *clip_path = box->getAttribute("clip-path");
1279 for ( SPObject *obj = box->firstChild(); obj; obj = obj->getNext() ) {
1285 g_warning("Non-side item encountered as child of a 3D box.");
1289 // add the new group to the box's parent and set remembered position
1290 SPObject *parent = box->parent;
1299 box->deleteObject(true);
1313 // We could put more details about the 3d box here
1318 box3d_push_back_corner_pair(SPBox3D const *box, std::list<std::pair<Geom::Point, Geom::Point> > &pts, int c1, int c2) {
1319 pts.push_back(std::make_pair(box3d_get_corner_screen(box, c1, false),
1320 box3d_get_corner_screen(box, c2, false)));