mirror of
git://projects.qi-hardware.com/cae-tools.git
synced 2024-12-23 08:59:53 +02:00
733332da8c
- solidify/overlap.h, solidify/overlap.c (edit_top, overlap_edit): select the face to rotate and shift - solidify/overlap.c (scroll_event): select face to manipulate based on edit_top - solidify/solidify.c (a_b, gui_buttons): new button B+A to select the bottom face for editing - solidify/solidify.c clicked): call overlap_edit to select face to edit
182 lines
3.7 KiB
C
182 lines
3.7 KiB
C
/*
|
|
* solidify.c - Merge two opposing faces of a part into a solid
|
|
*
|
|
* Written 2010 by Werner Almesberger
|
|
* Copyright 2010 Werner Almesberger
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
* (at your option) any later version.
|
|
*/
|
|
|
|
|
|
#include <stdlib.h>
|
|
#include <stdio.h>
|
|
#include <unistd.h>
|
|
#include <string.h>
|
|
#include <locale.h>
|
|
#include <gtk/gtk.h>
|
|
|
|
#include "face.h"
|
|
#include "solid.h"
|
|
#include "project.h"
|
|
#include "style.h"
|
|
#include "level.h"
|
|
#include "overlap.h"
|
|
|
|
|
|
static struct project *prj;
|
|
static const struct face *active; /* NULL if overlapping */
|
|
static GtkWidget *canvas, *a_b;
|
|
|
|
|
|
static void clicked(GtkButton *button, gpointer user_data)
|
|
{
|
|
struct face *face = user_data;
|
|
|
|
if (!face)
|
|
overlap_edit(button == GTK_BUTTON(a_b));
|
|
|
|
if (active == face)
|
|
return;
|
|
|
|
gtk_widget_destroy(gtk_bin_get_child(GTK_BIN(canvas)));
|
|
|
|
if (face)
|
|
level(canvas, face);
|
|
else
|
|
overlap(canvas, &prj->s);
|
|
active = face;
|
|
|
|
gtk_widget_show_all(canvas);
|
|
}
|
|
|
|
|
|
static GtkWidget *gui_buttons(void)
|
|
{
|
|
GtkWidget *vbox, *but;
|
|
|
|
vbox = gtk_vbox_new(FALSE, 0);
|
|
|
|
but = gtk_button_new_with_label("A");
|
|
gtk_box_pack_start(GTK_BOX(vbox), but, FALSE, FALSE, 0);
|
|
g_signal_connect(G_OBJECT(but), "clicked",
|
|
G_CALLBACK(clicked), prj->s.a);
|
|
|
|
but = gtk_button_new_with_label("B");
|
|
gtk_box_pack_start(GTK_BOX(vbox), but, FALSE, FALSE, 0);
|
|
g_signal_connect(G_OBJECT(but), "clicked",
|
|
G_CALLBACK(clicked), prj->s.b);
|
|
|
|
a_b = gtk_button_new_with_label("A+B");
|
|
gtk_box_pack_start(GTK_BOX(vbox), a_b, FALSE, FALSE, 0);
|
|
g_signal_connect(G_OBJECT(a_b), "clicked",
|
|
G_CALLBACK(clicked), NULL);
|
|
|
|
but = gtk_button_new_with_label("B+A");
|
|
gtk_box_pack_start(GTK_BOX(vbox), but, FALSE, FALSE, 0);
|
|
g_signal_connect(G_OBJECT(but), "clicked",
|
|
G_CALLBACK(clicked), NULL);
|
|
|
|
return vbox;
|
|
}
|
|
|
|
|
|
static gboolean key_press_event(GtkWidget *widget, GdkEventKey *event,
|
|
gpointer data)
|
|
{
|
|
if (event->keyval == 'q')
|
|
gtk_main_quit();
|
|
return TRUE;
|
|
}
|
|
|
|
|
|
static void gui(void)
|
|
{
|
|
GtkWidget *root, *hbox, *buttons;
|
|
|
|
root = gtk_window_new(GTK_WINDOW_TOPLEVEL);
|
|
gtk_window_set_position(GTK_WINDOW(root), GTK_WIN_POS_CENTER);
|
|
|
|
hbox = gtk_hbox_new(FALSE, 0);
|
|
gtk_container_add(GTK_CONTAINER(root), hbox);
|
|
|
|
canvas = gtk_event_box_new();
|
|
gtk_box_pack_start(GTK_BOX(hbox), canvas, FALSE, FALSE, 0);
|
|
|
|
/* initialize root->window */
|
|
gtk_widget_show_all(root);
|
|
|
|
buttons = gui_buttons();
|
|
gtk_box_pack_start(GTK_BOX(hbox), buttons, TRUE, TRUE, 0);
|
|
|
|
level(canvas, prj->s.a);
|
|
active = prj->s.a;
|
|
|
|
init_style(root->window);
|
|
|
|
gtk_widget_show_all(root);
|
|
|
|
g_signal_connect(G_OBJECT(root), "key-press-event",
|
|
G_CALLBACK(key_press_event), NULL);
|
|
g_signal_connect(G_OBJECT(root), "destroy",
|
|
G_CALLBACK(gtk_main_quit), NULL);
|
|
|
|
gtk_main();
|
|
}
|
|
|
|
|
|
static void usage(const char *name)
|
|
{
|
|
fprintf(stderr, "usage: %s project [top bottom dist]\n", name);
|
|
fprintf(stderr, " %s -p project\n", name);
|
|
exit(1);
|
|
}
|
|
|
|
|
|
int main(int argc, char **argv)
|
|
{
|
|
double dist;
|
|
int do_pov = 0;
|
|
|
|
gtk_init(&argc, &argv);
|
|
setlocale(LC_ALL, "C"); /* damage control */
|
|
|
|
switch (argc) {
|
|
case 2:
|
|
prj = load_project(argv[1]);
|
|
break;
|
|
case 3:
|
|
if (strcmp(argv[1], "-p"))
|
|
usage(*argv);
|
|
prj = load_project(argv[2]);
|
|
do_pov = 1;
|
|
break;
|
|
case 5:
|
|
dist = atof(argv[4]);
|
|
prj = new_project(argv[1], argv[2], argv[3], dist);
|
|
break;
|
|
default:
|
|
usage(*argv);
|
|
}
|
|
|
|
if (do_pov) {
|
|
const char *slash = strrchr(prj->name, '/');
|
|
char tmp[1000], tmp2[1000]; /* @@@ enough */
|
|
|
|
strcpy(tmp, slash ? slash+1 : prj->name);
|
|
if (strchr(tmp, '.'))
|
|
*strchr(tmp, '.') = 0;
|
|
sprintf(tmp2, "%s.inc", tmp);
|
|
povray(tmp2, tmp, &prj->s);
|
|
return 0;
|
|
}
|
|
|
|
gui();
|
|
|
|
save_project(prj);
|
|
|
|
return 0;
|
|
}
|