Ejemplo n.º 1
0
int order_pridir(){
	//Check if there is a request at current floor in right direction.
	if(order_check_request_current_floor()) {
		return 0;
	}

	//Check if there is a request above
	else if(order_check_request_above() && (get_last_dir()==UP)){
		return 1;
	}
	//Check if there is a request below
	else if(order_check_request_below() && (get_last_dir()==DOWN)) {
		return -1;
	}
	//Check if there is a request above when the direction is DOWN. This is served if there are no requests below.
	else if(order_check_request_above() && !(order_check_request_below())) {
		return 1;
	}
	//Check if there is a request below when the direction is UP. This is served if there are no requests above.
	else if(order_check_request_below() && !(order_check_request_above())) {
		return -1;
	}
	else{
		return 0;
	}
}
Ejemplo n.º 2
0
int order_should_stop(){
	int current_floor = control_getcurpos();
	if(current_floor==BETWEEN_FLOORS){
		return 0;
	}
	if(current_floor==N_FLOORS-1 || current_floor==0) {
		return 1;
	}
	struct node * head = gethead();
	if(get_last_dir()==UP){
		if((head->elevinfo.current_orders[current_floor][COMMAND].active==1) || (head->elevinfo.current_orders[current_floor][CALL_UP].active==1)) {
			return 1;
		}
		else if(!order_check_request_above()){
			return 1;
		}
	}
	else if(get_last_dir()==DOWN) {
		if((head->elevinfo.current_orders[current_floor][COMMAND].active==1) || (head->elevinfo.current_orders[current_floor][CALL_DOWN].active==1)) {
			return 1;
		}
		else if(!order_check_request_below()){
			return 1;
		}
	}
	return 0;
}
Ejemplo n.º 3
0
int order_check_request_current_floor(){
	int current_floor = control_getcurpos();
	if(current_floor==BETWEEN_FLOORS)
	    return 0;

	if(get_last_dir()==UP){
		return(head.elevinfo.current_orders[current_floor][COMMAND].active || head.elevinfo.current_orders[current_floor][CALL_UP].active);
	}
	else if(get_last_dir()==DOWN) {
		return(head.elevinfo.current_orders[current_floor][COMMAND].active || head.elevinfo.current_orders[current_floor][CALL_DOWN].active);
	}
	return 0;
}
Ejemplo n.º 4
0
void order_reset_current_floor(){
	int floor = control_getcurpos();
	if(floor!=BETWEEN_FLOORS){
		if ((floor == 0) && head.elevinfo.current_orders[floor][CALL_UP].active) order_register_as_done(floor, CALL_UP);
		if ((floor == N_FLOORS-1) && head.elevinfo.current_orders[floor][CALL_DOWN].active) order_register_as_done(floor, CALL_DOWN);
		if(head.elevinfo.current_orders[floor][COMMAND].active)	order_register_as_done(floor, COMMAND);
		else{
			if(head.elevinfo.current_orders[floor][CALL_UP].active!=head.elevinfo.current_orders[floor][CALL_DOWN].active ){
				if(head.elevinfo.current_orders[floor][CALL_UP].active ){
					order_register_as_done(floor, CALL_UP);
					set_last_dir(UP);
				}
				else{
					order_register_as_done(floor, CALL_DOWN);
					set_last_dir(DOWN);
				}
			}
		}
		if((get_last_dir() == UP) && head.elevinfo.current_orders[floor][CALL_UP].active ) order_register_as_done(floor, CALL_UP);
		else if((get_last_dir() == DOWN) && head.elevinfo.current_orders[floor][CALL_DOWN].active ) order_register_as_done( floor, CALL_DOWN);
	}

}
Ejemplo n.º 5
0
int order_check_request_below(){
	int current_floor = control_getcurpos();
	if(current_floor==BETWEEN_FLOORS){
	    if(get_last_dir()==UP) current_floor = last_floor+1;  	/* Then the checks are to be done relative to floor above elevator.	*/
	    else current_floor = last_floor;     					/* Else check requests relative to the last floor passed.			*/
	}
	if(current_floor == 0) return 0;
	int floor, panel_counter;
	for(panel_counter = CALL_UP; panel_counter<=COMMAND; panel_counter++){
		for(floor = current_floor-1; floor>=0; floor--){
			if(head.elevinfo.current_orders[floor][panel_counter].active==1) return 1;
		}
	}
	return 0;
}
Ejemplo n.º 6
0
int order_check_request_above(){
	int current_floor = control_getcurpos();
	if(current_floor==BETWEEN_FLOORS){
	    if(get_last_dir()==UP) current_floor = last_floor;	/* Means elevator is probably between last_floor and last_floor+1*
	    													 * Then checks are to be done relative to floor recently passed. */
	    else current_floor = last_floor-1;					/* Else check relative to the floor below elevator.*/
	}
	else last_floor = current_floor;
	int floor = 0;
	if(current_floor == N_FLOORS-1)	return 0;
	int panel_counter = 0;
	for(panel_counter = CALL_UP; panel_counter<=COMMAND; panel_counter++){
		for(floor = current_floor+1; floor<N_FLOORS; floor ++){
			if(head.elevinfo.current_orders[floor][panel_counter].active==1) return 1;
		}
	}
	return 0;
}
Ejemplo n.º 7
0
static void
xml_planner_plugin_export (GtkAction *action,
			   gpointer   user_data)
{
	PlannerPlugin     *plugin;
	MrpProject        *project;
	GError            *error = NULL;
	GtkWidget         *file_chooser;
	GtkWidget         *dialog;
	gint               response;
	gchar             *filename = NULL;
	gchar             *real_filename;
	gchar             *last_dir;

	plugin = PLANNER_PLUGIN (user_data);

 try_again:

	file_chooser = gtk_file_chooser_dialog_new (_("Export"),
						    GTK_WINDOW (plugin->main_window),
						    GTK_FILE_CHOOSER_ACTION_SAVE,
						    GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
						    GTK_STOCK_SAVE, GTK_RESPONSE_OK,
						    NULL);
	gtk_window_set_modal (GTK_WINDOW (file_chooser), TRUE);

	last_dir = get_last_dir ();
	gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (file_chooser), last_dir);
	g_free (last_dir);

	response = gtk_dialog_run (GTK_DIALOG (file_chooser));
	if (response == GTK_RESPONSE_OK) {
		filename = gtk_file_chooser_get_filename (
			GTK_FILE_CHOOSER (file_chooser));
	}

	gtk_widget_destroy (file_chooser);

	if (filename) {
		if (!g_str_has_suffix (filename, ".mrproject") && !g_str_has_suffix (filename, ".planner")) {
			/* Add the old extension for old format files. */
			real_filename = g_strconcat (filename, ".mrproject", NULL);
		} else {
			real_filename = g_strdup (filename);
		}

		if (g_file_test (real_filename, G_FILE_TEST_EXISTS)) {
			dialog = gtk_message_dialog_new (GTK_WINDOW (plugin->main_window),
							 GTK_DIALOG_MODAL |
							 GTK_DIALOG_DESTROY_WITH_PARENT,
							 GTK_MESSAGE_WARNING,
							 GTK_BUTTONS_YES_NO,
							 _("File \"%s\" exists, "
							   "do you want to overwrite it?"),
							 real_filename);

			response = gtk_dialog_run (GTK_DIALOG (dialog));
			gtk_widget_destroy (dialog);

			switch (response) {
			case GTK_RESPONSE_YES:
				break;
			default:
				g_free (real_filename);
				goto try_again;
			}
		}
	}

	if (!filename) {
		return;
	}

	project = planner_window_get_project (plugin->main_window);

	if (!mrp_project_export (project, real_filename,
				 "Planner XML pre-0.12",
				 TRUE,
				 &error)) {
		g_warning ("Error while export to Planner XML: %s", error->message);
	}

	last_dir = g_path_get_dirname (real_filename);
	planner_conf_set_string (CONF_MAIN_LAST_XML_EXPORT_DIR, last_dir, NULL);
	g_free (last_dir);

	g_free (real_filename);
	g_free (filename);
}