mirror of
git://projects.qi-hardware.com/cae-tools.git
synced 2025-04-21 12:27:27 +03:00
Initial commit. For older history, see project ben-scans.
http://projects.qi-hardware.com/index.php/p/ben-scans/
This commit is contained in:
163
solidify/solidify.c
Normal file
163
solidify/solidify.c
Normal file
@@ -0,0 +1,163 @@
|
||||
/*
|
||||
* 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, FALSE, FALSE, 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);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
double dist;
|
||||
|
||||
gtk_init(&argc, &argv);
|
||||
setlocale(LC_ALL, "C"); /* damage control */
|
||||
|
||||
switch (argc) {
|
||||
case 2:
|
||||
prj = load_project(argv[1]);
|
||||
break;
|
||||
case 5:
|
||||
dist = atof(argv[4]);
|
||||
prj = new_project(argv[1], argv[2], argv[3], dist);
|
||||
break;
|
||||
default:
|
||||
usage(*argv);
|
||||
}
|
||||
|
||||
gui();
|
||||
|
||||
save_project(prj);
|
||||
|
||||
if (!isatty(1)) {
|
||||
const char *slash = strrchr(prj->name, '/');
|
||||
char tmp[1000]; /* @@@ enough */
|
||||
|
||||
strcpy(tmp, slash ? slash+1 : prj->name);
|
||||
if (strchr(tmp, '.'))
|
||||
*strchr(tmp, '.') = 0;
|
||||
povray(tmp, &prj->s);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user