예제 #1
0
static void show_cylinder(cylinder_t *cyl, struct cylinder_widget *cylinder)
{
	const char *desc;
	int ml, mbar;
	double o2;

	/* Don't show uninitialized cylinder widgets */
	if (!cylinder->description)
		return;

	desc = cyl->type.description;
	if (!desc)
		desc = "";
	ml = cyl->type.size.mliter;
	mbar = cyl->type.workingpressure.mbar;
	add_cylinder(cylinder, desc, ml, mbar);

	set_cylinder_type_spinbuttons(cylinder,
		cyl->type.size.mliter, cyl->type.workingpressure.mbar);
	set_cylinder_pressure_spinbuttons(cylinder,
		cyl->start.mbar, cyl->end.mbar);
	o2 = cyl->gasmix.o2.permille / 10.0;
	gtk_widget_set_sensitive(cylinder->o2, !!o2);
	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(cylinder->gasmix_button), !!o2);
	if (!o2)
		o2 = 21.0;
	gtk_spin_button_set_value(GTK_SPIN_BUTTON(cylinder->o2), o2);
}
예제 #2
0
t_cylinder	*get_cylinders(int fd)
{
	int			r;
	char		*line;
	t_cylinder	*c;

	c = NULL;
	while ((r = get_next_line(fd, &line)) > 0 && ft_strcmp(line, "----------"))
	{
		if (!ft_strcmp("new:", line))
		{
			if (c == NULL)
				c = get_cylinder(fd);
			else
				add_cylinder(c, get_cylinder(fd));
		}
	}
	if (r == -1)
		exit(-1);
	return (c);
}
예제 #3
0
static void fill_cylinder_info(struct cylinder_widget *cylinder, cylinder_t *cyl, const char *desc,
		double volume, double pressure, double start, double end, int o2, int he)
{
	int mbar, ml;

	if (output_units.pressure == PSI) {
		pressure = psi_to_bar(pressure);
		start = psi_to_bar(start);
		end = psi_to_bar(end);
	}

	if (pressure && output_units.volume == CUFT) {
		volume = cuft_to_l(volume);
		volume /= bar_to_atm(pressure);
	}

	ml = volume * 1000 + 0.5;
	mbar = pressure * 1000 + 0.5;

	/* Ignore obviously crazy He values */
	if (o2 + he > 1000)
		he = 0;

	/* We have a rule that normal air is all zeroes */
	if (!he && o2 > 208 && o2 < 211)
		o2 = 0;

	cyl->type.description = desc;
	cyl->type.size.mliter = ml;
	cyl->type.workingpressure.mbar = mbar;
	cyl->start.mbar = start * 1000 + 0.5;
	cyl->end.mbar = end * 1000 + 0.5;
	cyl->gasmix.o2.permille = o2;
	cyl->gasmix.he.permille = he;

	/*
	 * Also, insert it into the model if it doesn't already exist
	 */
	add_cylinder(cylinder, desc, ml, mbar);
}
예제 #4
0
// Process a production string and generate form
void L_draw(const context& Context, const k3d::signed_axis Orientation)
{
	// Save values
	k3d::double_t thick_l = 0;
	k3d::double_t ang_l = 0;
	k3d::double_t dis_l = 0;
	k3d::double_t dis2_l = 0;
	k3d::double_t trope_l = 0;

	bool poly_on = false;

	// Setup vectors
	k3d::point3 pos(0.0, 0.0, 0.0);
	k3d::vector3 fow(0.0, 0.0, 1.0);
	k3d::vector3 lef(0.0, 1.0, 0.0);
	k3d::vector3 upp(1.0, 0.0, 0.0);

	trope = k3d::normalize(trope);

	for(unsigned long i = 0; i < object_string.size(); i++)
	{
		// Overflow
		if(polcount > poly_limit)
			break;

		// The next char in the string
		char next = object_string[i + 1];

		// The current char in the string
		switch(object_string[i])
		{
			default:
				break;

			// Marks last recursion level during growing phase
			case '@':
				last_recur = !last_recur;
				if(last_recur)
				{
					// Store all variables and do fraction
					thick_l = thick;
					ang_l = ang;
					dis_l = dis;
					dis2_l = dis2;
					trope_l = trope_amount;

					dis *= fraction;
					dis2 *= fraction;
					thick *= fraction;
					ang *= fraction;
					trope_amount *= fraction;
				}
				else
				{
					// Restore
					thick = thick_l;
					ang = ang_l;
					dis = dis_l;
					dis2 = dis2_l;
					trope_amount = trope_l;
				}
			break;

			case '+':
				save.ang = ang;
				if(next == '(')
				{
					ang = 0.017453 * parse_value(i);
					if(last_recur)
						ang *= fraction;
				}

				set_rotation_matrix(-ang, upp);
				fow = rotate(fow);
				lef = rotate(lef);
				ang = save.ang;
			break;

			case '-':
				save.ang = ang;
				if(next == '(')
				{
					ang = 0.017453 * parse_value(i);
					if(last_recur)
						ang *= fraction;
				}

				set_rotation_matrix(ang, upp);
				fow = rotate(fow);
				lef = rotate(lef);
				ang = save.ang;
			break;

			case '~':
			{
				k3d::double_t r = 6.0;
				if(next == '(')
					r = 0.017453 * parse_value(i);
				else if(rand_set)
					r = 0.017453 * rand_amount;

				k3d::double_t a = Rnd() * r * 2.0 - r;
				set_rotation_matrix(a, upp);
				fow = rotate(fow);
				lef = rotate(lef);
				a = (Rnd() * r * 2.0) - r;
				set_rotation_matrix(a, lef);
				fow = rotate(fow);
				upp = rotate(upp);
				a = (Rnd() * r * 2.0) - r;
				set_rotation_matrix(a, fow);
				lef = rotate(lef);
				upp = rotate(upp);
			}
			break;

			case 't':
			{
				if((fow[0] == 0.0) && (fow[1] == 0.0))
					break;

				save.tr = tr;
				if(trope_set)
					tr = trope_amount;

				if(next == '(')
				{
					tr = parse_value(i);
					if(last_recur)
						tr *= fraction;
				}

				trope = fow;
				trope[0] = -trope[0];
				trope[1] = -trope[1];
				trope[2] = 0.0;
				trope = k3d::normalize(trope);
				k3d::double_t r = tr * (fow * trope);
				set_rotation_matrix(-r, lef);
				fow = rotate(fow);
				upp = rotate(upp);
				tr = save.tr;
			}
			break;

			case '$':
			{
				k3d::vector3 v = fow - sky;
				if(v.length() == 0.0)
					break;

				lef = fow ^ sky;
				upp = fow ^ lef;
				if(upp[2] < 0.0)
				{
					upp = -upp;
					lef = -lef;
				}
			}
			break;

			case '&':
				save.ang = ang;
				if(next == '(')
				{
					ang = 0.017453 * parse_value(i);
					 if(last_recur)
					ang *= fraction;
				}

				set_rotation_matrix(ang, lef);
				fow = rotate(fow);
				upp = rotate(upp);
				ang = save.ang;
			break;

			case '^':
				save.ang = ang;
				if(next == '(')
				{
					ang = 0.017453 * parse_value(i);
					if(last_recur)
						ang *= fraction;
				}

				set_rotation_matrix(-ang, lef);
				fow = rotate(fow);
				upp = rotate(upp);
				ang = save.ang;
			break;

			case '<':
				save.ang = ang;
				if(next == '(')
				{
					ang = 0.017453 * parse_value(i);
					if(last_recur)
						ang *= fraction;
				}

				set_rotation_matrix(-ang, fow);
				lef = rotate(lef);
				upp = rotate(upp);
				ang = save.ang;
			break;

			case '>':
				save.ang = ang;
				if(next == '(')
				{
					ang = 0.017453 * parse_value(i);
					if(last_recur)
						ang *= fraction;
				}

				set_rotation_matrix(ang, fow);
				lef = rotate(lef);
				upp = rotate(upp);
				ang = save.ang;
			break;

			case '%':
				set_rotation_matrix(3.141592654, fow);
				lef = rotate(lef);
				upp = rotate(upp);
			break;

			case '|':
				set_rotation_matrix(3.141592654, upp);
				fow = rotate(fow);
				lef = rotate(lef);
			break;

			case '!':
				if(next == '(')
				{
					if(last_recur)
						thick *= 1.0 + fraction * (parse_value(i) - 1.0);
					else
						thick *= parse_value(i);
				}
				else
				{
					if(last_recur)
						thick *= 1.0 + fraction * (0.7 - 1.0);
					else
						thick *= 0.7;
				}
			break;

			case '?':
				if(next == '(')
				{
					if(last_recur)
						thick *= 1.0 + fraction * (parse_value(i) - 1.0);
					else
						thick *= parse_value(i);
				}
				else
				{
					if(last_recur)
						thick /= 1.0 + fraction * (0.7 - 1.0);
					else
						thick /= 0.7;
				}
			break;

			case ':':
				if(next == '(')
				{
					if(last_recur)
						ang *= 1.0 + fraction * (parse_value(i) - 1.0);
					else
						ang *= parse_value(i);
				}
				else
				{
					if(last_recur)
						ang *= 1.0 + fraction * (0.9 - 1.0);
					else
						ang *= 0.9;
				}
			break;

			case ';':
				if(next == '(')
				{
					if(last_recur)
						ang *= 1.0 + fraction * (parse_value(i) - 1.0);
					else
						ang *= parse_value(i);
				}
				else
				{
					if(last_recur)
						ang /= 1.0 + fraction * (0.9 - 1.0);
					else
						ang /= 0.9;
				}
			break;

			case '\'':
				if(next == '(')
				{
					k3d::double_t r = parse_value(i);
					if(last_recur)
					{
						dis *= 1.0 + fraction * (r - 1.0);
						dis2 *= 1.0 + fraction * (r - 1.0);
					}
					else
					{
						dis *= r;
						dis2 *= r;
					}
				}
				else
				{
					if(last_recur)
					{
						dis *= 1.0 + fraction * (0.9 - 1.0);
						dis2 *= 1.0 + fraction * (0.9 - 1.0);
					}
					else
					{
						dis *= 0.9;
						dis2 *= 0.9;
					}
				}
			break;

			case '"':
				if(next == '(')
				{
					k3d::double_t r = parse_value(i);
					if(last_recur)
					{
						dis *= 1.0 + fraction * (r - 1.0);
						dis2 *= 1.0 + fraction * (r - 1.0);
					}
					else
					{
						dis *= r;
						dis2 *= r;
					}
				}
				else
				{
					if(last_recur)
					{
						dis /= 1.0 + fraction * (0.9 - 1.0);
						dis2 /= 1.0 + fraction * (0.9 - 1.0);
					}
					else
					{
						dis /= 0.9;
						dis2 /= 0.9;
					}
				}
			break;

			case 'Z':
			{
				save.dis2 = dis2;
				if(next == '(')
				{
					dis2 = parse_value(i);
					if(last_recur)
						dis2 *= fraction;
				}

				k3d::point3 end = pos + dis2 * fow;
				if(closed_form)
					add_cylinder(pos, end, upp, col, Context, Orientation);
				else
					add_cube(pos, end, upp, col, Context, Orientation);

				pos = end;
				dis2 = save.dis2;
			}
			break;

			case 'F':
			{
				save.dis = dis;
				if(next == '(')
				{
					dis = parse_value(i);
					if(last_recur)
						dis *= fraction;
				}

				k3d::point3 end = pos + dis * fow;
				if(closed_form)
					add_cylinder(pos, end, upp, col, Context, Orientation);
				else
					add_cube(pos, end, upp, col, Context, Orientation);

				pos = end;
				dis = save.dis;
			}
			break;

			case '[':
			{
				s_rec new_rec;
				new_rec.pos = pos;
				new_rec.fow = fow;
				new_rec.lef = lef;
				new_rec.upp = upp;
				new_rec.col = col;
				new_rec.dis = dis;
				new_rec.dis2 = dis2;
				new_rec.ang = ang;
				new_rec.thick = thick;
				new_rec.tr = tr;

				if(closed_form)
				{
					new_rec.last = last;
					new_rec.last_col = last_col;
					for(unsigned long j = 0; j < 8; j++)
						new_rec.last_v[j] = last_v[j];
				}

				if(stack.size() < max_stack_size)
					stack.push(new_rec);
			}
			break;

			case ']':
			{
				if(!stack.size())
					break;

				s_rec old_rec = stack.top();
				pos = old_rec.pos;
				fow = old_rec.fow;
				lef = old_rec.lef;
				upp = old_rec.upp;
				col = old_rec.col;
				dis = old_rec.dis;
				dis2 = old_rec.dis2;
				ang = old_rec.ang;
				thick = old_rec.thick;
				tr = old_rec.tr;
				if(closed_form)
				{
					last = old_rec.last;
					last_col = old_rec.last_col;
					for(unsigned long j = 0; j < 8; j++)
						last_v[j] = old_rec.last_v[j];
				}

				stack.pop();
			}
			break;

			case '{':
				if(poly_on)
				{
					vectors_t new_rec = vertices;
					if(pstack.size() < max_stack_size)
						pstack.push(new_rec);
				}

				poly_on = true;

				vertices.clear();
				vertices.push_back(pos);
			break;

			case 'f':
				save.dis = dis;
				if(next == '(')
				{
					dis = parse_value(i);
					if(last_recur)
						dis *= fraction;
				}

				pos = pos + dis * fow;
				if(poly_on)
					vertices.push_back(pos);

				dis = save.dis;
			break;

			case '.':
				if(poly_on)
					vertices.push_back(pos);
			break;

			case 'g':
				save.dis = dis;
				if(next == '(')
				{
					dis = parse_value(i);
					if(last_recur)
						dis *= fraction;
				}

				pos = pos + dis * fow;
				dis = save.dis;
			break;

			case 'z':
				save.dis2 = dis2;
				if(next == '(')
				{
					dis2 = parse_value(i);
					if(last_recur)
						dis2 *= fraction;
				}

				pos = pos + dis2 * fow;
				if(poly_on)
					vertices.push_back(pos);

				dis2 = save.dis2;
			break;

			case '}':
				polygons.clear();
				if(vertices.size() > 3)
				{
					for(unsigned long j = 1; j < vertices.size() - 1; j++)
						polygons.push_back(polygon(0, j, j + 1, j + 1));

					add_geometry(col, Context);
				}

				poly_on = false;
				if(pstack.size() > 0)
				{
					vertices.clear();

					if(!pstack.size())
						break;

					vertices = pstack.top();
					pstack.pop();

					poly_on = true;
				}
			break;

			case 'c':
				if(next == '(')
					col = (unsigned long)parse_value(i);
				else
					col++;
			break;
		}
	}
}