1
0
mirror of git://projects.qi-hardware.com/cae-tools.git synced 2024-12-23 04:13:20 +02:00
cae-tools/solidify/solidify.c
Werner Almesberger 12f5aa2188 Cleaned up POV-Ray file handling. New use: solidify -p project
- solidify/Makefile (pov, disp, main.pov): call the main POV-Ray file
  $(NAME).pov, not main.pov
- solidify/Makefile: generate $(NAME).inc
- solidify/solid.h, solidify/povray.c (povray_face, povray): accept file
  name as argument and write to the specified file instead of stdout
- solidify/povray.c (height_field): added file error handling
- solidify/povray.c (height_field, povray): removed useless matrix argument
- solidify/solidify.c (usage, main): new invocation "-p project" to generate
  POV-Ray output. Removed old isatty() hack.
- solidify/Makefile: updated to use solidify -p to generate POV-Ray output
2010-09-27 00:54:57 -03:00

174 lines
3.5 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;
static void clicked(GtkButton *button, gpointer user_data)
{
struct face *face = user_data;
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);
but = gtk_button_new_with_label("A+B");
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;
}