Ejemplo n.º 1
0
    int Creature::main(int argc, char** argv) {
        (void) argc;
        (void) argv;
        BasicCreature creature(1);

        QDomDocument doc;
        creature.toXml(doc);
        QString xml = doc.toString();
        //        std::cout << xml.toStdString() << std::endl;
        BDEBUG(xml.toStdString());

        doc.clear();
        QString * error_msg = new QString();
        int* error_line = new int();
        int* error_col = new int();
        doc.setContent(xml, error_msg, error_line, error_col);
        std::cout << "Error: " << error_msg->toStdString() << " at [" << *error_line << " , "
                << *error_col << "]" << std::endl;
        delete error_msg;
        delete error_line;
        delete error_col;

        QDomElement root = doc.firstChild().toElement();
        //        creature.fromXml(root);
        doc.clear();
        creature.toXml(doc);
        xml = doc.toString();
        BDEBUG("******************************");
        BDEBUG(xml.toStdString());
        std::cout << xml.toStdString() << std::endl;
        return 0;
    }
Ejemplo n.º 2
0
    TerminalNode * GpModel::evaluate( const Node* node, FunctionListener & listener ) {
        TerminalNode* result = NULL;
        const FunctionNode* function = dynamic_cast<const FunctionNode*> (node);
        if (function) {
            FunctionNode* tmp_function = new FunctionNode(function->getArity());
            tmp_function->setType(function->getType());
            for (int i = 0; i < function->getArity(); ++i) {
                evaluate(function->getChild(i), listener)->moveTo(tmp_function, i);
            }
            listener.evaluate(*tmp_function);
            for (int i = 0; i < tmp_function->getArity() - 1; ++i) {
                delete tmp_function->getChild(i);
            }

            result = dynamic_cast<TerminalNode*> (tmp_function->getChild(tmp_function->getArity() - 1));
            assert(result);
            result->remove();
            delete tmp_function;
        } else {
            const TerminalNode* terminal = dynamic_cast<const TerminalNode*> (node);
            if (terminal) {
                result = terminal->clone();
            } else {
                if (node == NULL) {
                    BDEBUG("Node is NULL");
                } else {
                    BDEBUG("Unknown type of Node");
                }
                assert(0);
            }
        }
        return result;
    }
Ejemplo n.º 3
0
static response_status 
writev_bucket(write_bucket *data)
{
    size_t w;
    int i = 0;
    Py_BEGIN_ALLOW_THREADS
#ifdef DEVELOP
    BDEBUG("\nwritev_bucket fd:%d", data->fd);
    printf("\x1B[34m");
    writev_log(data);
    printf("\x1B[0m\n");
#endif
    w = writev(data->fd, data->iov, data->iov_cnt);
    BDEBUG("writev fd:%d ret:%d total_size:%d", data->fd, (int)w, data->total);
    Py_END_ALLOW_THREADS
    if(w == -1){
        //error
        if (errno == EAGAIN || errno == EWOULDBLOCK) {
            BDEBUG("try again later");
            return STATUS_SUSPEND;
        }else{
            //ERROR
            PyErr_SetFromErrno(PyExc_IOError);
            /* write_error_log(__FILE__, __LINE__); */
            call_error_logger();
            return STATUS_ERROR;
        }
    }if(w == 0){
        data->sended = 1;
        return STATUS_OK;
    }else{
        if(data->total > w){
            for(; i < data->iov_cnt;i++){
                if(w > data->iov[i].iov_len){
                    //already write
                    w -= data->iov[i].iov_len;
                    data->iov[i].iov_len = 0;
                }else{
                    data->iov[i].iov_base += w;
                    data->iov[i].iov_len = data->iov[i].iov_len - w;
                    break;
                }
            }
            data->total = data->total - w;
            BDEBUG("writev_bucket write %d progress %d/%d", (int)w, data->total, data->total_size);
            //resume
            // again later
            return writev_bucket(data);
        }
        data->sended = 1;
    }
    data->sended = 1;
    return STATUS_OK;
}
Ejemplo n.º 4
0
 int BasicDebug::main( int argc, char** argv ) {
     (void)argc; (void)argv;
     BDEBUG("Esto es un mensaje");
     DEBUGM;
     BDEBUG("Esto es otro mensaje");
     DEBUGM;
     BDEBUG("Esto es un mensaje?");
     DEBUGM;
     std::string fk(__FILE__);
     std::string kx(__FILE__);
     //            std::string x (__LINE__);
     std::cout << fk + kx << std::endl;
     return 0;
 }
Ejemplo n.º 5
0
static PyObject*
ConnectionObject_autocommit(ConnectionObject *self, PyObject *args)
{
    int flag, status = 1;
    char query[256];

    drizzle_return_t ret;
    drizzle_result_st result;

    if (!PyArg_ParseTuple(args, "i", &flag)) {
        return NULL;
    }

    DEBUG("autocommit %d", flag);
    snprintf(query, 256, "SET AUTOCOMMIT=%d;", flag);
    BDEBUG("query %s", query);
    
    while(status){
        (void)drizzle_query(self->con, &result, query, 256, &ret);
        status = io_wait(self->con, ret);
        if (status == -1){
            goto error;
        }
    }

    drizzle_result_free(&result);
    Py_RETURN_NONE;
error:
    drizzle_result_free(&result);
    PyErr_SetString(PyExc_IOError, drizzle_error(drizzle));
    return NULL;
}
    BodyPart::eShape EvolutionOfMorphologyAndBehavior::getShape(double value) {
        //[0.0, 10.0) -> BOX
        //[10.0, 20.0) -> SPHERE
        //[20.0, 30.0) -> CAPSULE
        //[30.0, 40.0) -> CONE
        //[40.0, 50.0) -> CYLINDER
        //[50.0, 60.0) -> BOX
        //[60.0, 70.0) -> SPHERE
        //[70.0, 80.0) -> CAPSULE
        //[80.0, 90.0) -> CONE
        //[90.0, 100.0) -> CYLINDER

        if (value >= 0.0 && value < 20.0) {
            return BodyPart::S_BOX;
        }

        if (value >= 20.0 && value < 40.0) {
            return BodyPart::S_SPHERE;
        }

        if (value >= 40.0 && value < 60.0) {
            double p = 20.0 / 3.0; //Portion
            if (value >= 40.0 && value < 40.0 + p) {
                return BodyPart::S_CAPSULE_X;
            }
            if (value >= 40.0 + p && value < 40.0 + (2 * p)) {
                return BodyPart::S_CAPSULE_Y;
            }
            if (value >= 40.0 + (2 * p) && value < 60.0) {
                return BodyPart::S_CAPSULE_Z;
            }
        }

        if (value >= 60.0 && value < 80.0) {
            double p = 20.0 / 3.0; //Portion
            if (value >= 60.0 && value < 60.0 + p) {
                return BodyPart::S_CONE_X;
            }
            if (value >= 60.0 + p && value < 60.0 + (2 * p)) {
                return BodyPart::S_CONE_Y;
            }
            if (value >= 60.0 + (2 * p) && value < 80.0) {
                return BodyPart::S_CONE_Z;
            }
        }
        if (value >= 80.0 && value < 100.0) {
            double p = 20.0 / 3.0; //Portion
            if (value >= 80.0 && value < 80.0 + p) {
                return BodyPart::S_CYLINDER_X;
            }
            if (value >= 80.0 + p && value < 80.0 + (2 * p)) {
                return BodyPart::S_CYLINDER_Y;
            }
            if (value >= 80.0 + (2 * p) && value < 100.0) {
                return BodyPart::S_CYLINDER_Z;
            }
        }
        BDEBUG(TO_STRING(value));
        assert(0);
    }
Ejemplo n.º 7
0
 void GpModel::step( ) {
     TreeOfNodes** next = new TreeOfNodes*[getPopulationSize()];
     eGeneticOperator go = GO_NONE;
     for (int i = 0; i < getPopulationSize(); ++i) {
         go = nextGeneticOperator();
         switch (go) {
             case GO_CROSSOVER:
             {
                 TreeOfNodes* offspring = bestTournament().clone();
                 getCrossoverOperator()->crossover(*offspring, bestTournament());
                 next[i] = offspring;
             }
                 break;
             case GO_REPRODUCTION:
                 next[i] = getReproductionOperator()->reproduce(bestTournament());
                 break;
             case GO_MUTATION:
                 next[i] = getMutationOperator()->mutate(bestTournament(1), getTreeGenerator());
                 break;
             default:
                 BDEBUG(TO_STRING(go));
                 assert(0);
         }
     }
     for (int i = 0; i < getPopulationSize(); ++i) {
         delete _trees[i];
     }
     delete _trees;
     _trees = next;
 }
Ejemplo n.º 8
0
Archivo: linux.c Proyecto: OPSF/uClinux
int write_message(
	int format,	/* if true - extended message format */ 
	char *line	/* write parameter line */
	)
{
unsigned char data[8] = {8, 7, 6, 5, 4, 3 , 2, 1};
unsigned char *lptr;
int len = 0;
/* unsigned char **endptr; */
unsigned char *endptr;
canmsg_t tx;			/* build transmit message */



    /* May be some check is needed if we have a valid and useful message */

    lptr = &line[0];
    skip_space(lptr);

    tx.flags = 0;
    if(format == 1) {
	tx.flags |= MSG_EXT;
    } else {
    }
    if(*lptr == 'r' || *lptr == 'R') {
	tx.flags |= MSG_RTR;
	skip_word(lptr);
    }
    skip_space(lptr);
    tx.id  = strtoul(lptr, &endptr, 0);
    tx.cob = 0;

    while( lptr != endptr) {
        lptr = endptr;
        tx.data[len] = (signed char)strtol(lptr, &endptr, 0);
	if(lptr != endptr) len++;
	if (len == 8 ) break; 
    }

    tx.length = len;

BDEBUG("Transmit %d, RTR=%s, len=%d\n", tx.id,
			((tx.flags == 0) ? "F" : "T"),
			tx.length);
			
    len = write(can_fd, &tx, 1);

    if (len < 0) {
    	/* Write Error */
printf("Write Error: %d\n", len);
    }
    
    if (len == 0) {
    	/* Transmit Timeout */
printf("Write Error: Transmit fehlgeschlagen\n", len);
    }

    return 0;
}	
Ejemplo n.º 9
0
    Creature * Creature::fromXml(const std::string& xml, bool* ok) {
        QDomDocument doc;
        QString * error_msg = new QString();
        int* error_line = new int();
        int* error_col = new int();
        *ok = doc.setContent(QString(xml.c_str()), error_msg, error_line, error_col);
        if (!*ok) {
            BDEBUG("Error: " + error_msg->toStdString() +
                    " at [" + TO_STRING(*error_line) + " , " +
                    TO_STRING(*error_col) + "]");
        }
        delete error_msg;
        delete error_line;
        delete error_col;
        if (!*ok) {
            return NULL;
        }
        QDomElement root = doc.firstChild().toElement();

        return fromXml(root, ok);
    }
 void MainWindow::changedConstraintMotor( ) {
     getSimulationThread().getSimulator().getLock().lockForRead();
     Creature* creature = getSimulationThread().getSimulator().currentCreature();
     if (creature) {
         for (int i = 0; i < getUiInspector().lst_constraints->count(); ++i) {
             if (!getUiInspector().lst_constraints->item(i)->isSelected()) {
                 continue;
             }
             Constraint* constraint = &creature->getConstraint(i);
             if (getUiInspector().rbt_motor_x->isChecked()) {
                 loadConstraintValues(constraint, 0);
             } else if (getUiInspector().rbt_motor_y->isChecked()) {
                 loadConstraintValues(constraint, 1);
             } else if (getUiInspector().rbt_motor_z->isChecked()) {
                 loadConstraintValues(constraint, 2);
             } else {
                 BDEBUG("No Motor Selected");
             }
         }
     }
     getSimulationThread().getSimulator().getLock().unlock();
 }
Ejemplo n.º 11
0
Archivo: linux.c Proyecto: OPSF/uClinux
int set_up(void)
{
int ret;
char line[40];

    atexit(clean);

#ifndef SIM
    if(( can_fd = open(device,
			/* O_RDONLY */
			O_RDWR
    				)) < 0 ) {
	fprintf(stderr,"Error opening CAN device %s\n", device);
	exit(1);
    }
    if(o_bitrate != 0) {
	sprintf(line, " %d\n", o_bitrate);
	set_bitrate(line);
    }

#endif

    BDEBUG("message structure canmsg_t has %d bytes\n", sizeof(canmsg_t));


    if(!o_server) {
	/* set terminal mode */
	ret = system("stty cbreak -echo");
	if(ret != 0) {
	    fprintf(stderr, "  system(stty) returns %d\n", ret);
	}
    }
    /* pe-set time structures */
    gettimeofday(&tv_start, &tz);
    return 0;
}
Ejemplo n.º 12
0
    int GpModel::main( int argc, char** argv ) {
        GpModel model(30);
        model.setCrossoverOperator(new RegularAndFairSizeCrossover(200));
        model.setMutationOperator(new RegularMutation());
        model.setReproductionOperator(new RegularReproduction());
        model.getTreeGenerator().setPreferredDepth(2);
        model.getTreeGenerator().setPreferredMethod(TreeGenerator::M_RAMPED);
        model.setLowerFitnessBetter(true);

        model.create();

        model.setProbabilityCrossover(1.0);
        model.setProbabilityMutation(0.01);
        model.setProbabilityReproduction(1 - (model.getProbabilityCrossover() + model.getProbabilityMutation()));

        TestFunctionListener listener;
        //        for (int i = 0; i < 1000; ++i) {
        int i = 0;
        while (true) {
            ++i;
            double average_fitness = 0.0;
            double average_size = 0.0;
            for (int j = 0; j < model.getPopulationSize(); ++j) {
                TerminalNode* node = model.evaluate(model.getTree(j), listener);
                int fitness = node->getValue();
                delete node;
                model.getTree(j).setFitness(abs(fitness));
                average_fitness += abs(fitness);
                average_size += model.getTree(j).getSize();
            }
            BDEBUG("avg-size=" + TO_STRING(average_size / model.getPopulationSize()) + "\tavg-fitness=" + TO_STRING(average_fitness / model.getPopulationSize()) + "\tepoch=" + TO_STRING(i) + "");
            model.step();
            //            model.crossover();
        }
        return 0;
    }
Ejemplo n.º 13
0
Archivo: linux.c Proyecto: OPSF/uClinux
int server_event_loop(void)
{
/*----------------------------------------------------------------*/
SOCKET listenfd;                /* incoming connection socket fd  */
/* SOCKET asd; */
extern SOCKET server_fd;

int established = 0;

struct sockaddr_in servaddr;    /* incoming connection address */
struct sockaddr_in cliaddr;     /* incoming connection address */
int clilen;			/* size of client socket struct */

int maxfd;                      /* maximum fd (optimization for select) */
int maxi;                       /* number of clients ??? */
int i, j;                       /* looping index */
int rcnt;			/* receive cnt, number of received bytes */
char in_line[MAXLINE];		/* command input line from socket to horch */

    /*
     * Open a TCP socket (an Internet stream socket).
     * 
     */

    BDEBUG("Open socket\n");

    listenfd = socket(AF_INET, SOCK_STREAM, 0);
    if(listenfd < 0) {
	fprintf(stderr, "Socket open failed: %d\n", errno);
	goto TCP_SERVER_DONE;
    }
    BDEBUG("Got socket fd %d\n", listenfd);

    /*
    * Bind our local address so that the client can send to us.
    */
    memset((void *)&servaddr, 0, sizeof(servaddr));
    servaddr.sin_family         = AF_INET;
    /* servaddr.sin_addr.s_addr = htonl(INADDR_ANY); */
    servaddr.sin_port           = htons(o_portnumber);

    if (bind(listenfd, (struct sockaddr *) &servaddr, sizeof(servaddr)) < 0) {
	fprintf(stderr, "TCPserver: Socket bind failed: %d\n", errno);
	goto TCP_SERVER_DONE;
    }

    BDEBUG("\r\nHorch TCPserver, listening on port %d\r\n", o_portnumber);
    /*
    * loop forever (daemons never die!)
    */
    for ( ; ; ) {
	/*
	* Set socket to passive mode
	* and ask kernel to buffer upto LISTENQ (inet.h)
	*/
	/********************************************************************/
	/* API-Call listen for connections */
	/********************************************************************/
	BDEBUG("TCPserver: Listening for connection\n");

	if(listen(listenfd, 1) < 0) {
	    printf("TCPserver: Socket listen failed: %d\n", errno);
	}

	printf("\nWaiting for connections on port %d\n", o_portnumber);
	fflush(stdout);

	/*
	* Accept the client connection
	*/
        clilen = sizeof(cliaddr);
	server_fd = accept(listenfd, (struct sockaddr *) &cliaddr, 
		(socklen_t *)&clilen);
	if (server_fd < 0) {
	      printf("TCPserver: Socket accept failed: %d\n", errno);
	      goto TCP_SERVER_DONE;
	}
        /* save the new socketdescriptor */
        /* server_fd = outregs.x.ax; */
        established = 1;

	printf("New client: %s, port %u; Assigning fd#%d\n",
		    inet_ntoa(cliaddr.sin_addr), cliaddr.sin_port, server_fd);
	fflush(stdout);

        /* server_fd = asd; */	/* load static server_fd */ 


/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
{
canmsg_t rx[80];			/* receive buffer for read() */
canmsg_t *prx;			/* pointer to receive buffer */
fd_set rfds;
int got;				/* got this number of messages */
int i;
struct timeval tval;		/* use time out in W32 server */
static int select_flag = 0;	/* count erroneous select activity */ 


    while( read(can_fd, rx , 80 ) > 0); /* flush/remove old messages */
    reset_send_line();

    while(established)  {

	/* reinit everytime - see linux manual
	 * tval could be changed after select() call */
	tval.tv_sec = 0;		/* first try it with 1ms */
	tval.tv_usec = 1400;

        FD_ZERO(&rfds);
        FD_SET(can_fd, &rfds);		/* watch on fd for CAN */
#if 0
        FD_SET(0, &rfds);		/* watch on fd for stdin */
#endif
        FD_SET(server_fd, &rfds);	/* watch on fd for Client requests */

#if defined(TARGET_LINUX_PPC)
        /* select for:          read, write, except,  timeout */      
        if( select(FD_SETSIZE, &rfds, NULL, NULL,     &tval ) > 0 )
#else
        /* select for:          read, write, except, no-timeout */      
        if( select(FD_SETSIZE, &rfds, NULL, NULL,     NULL  ) > 0 )
#endif
        {
	    /* one of the read file descriptors has changed status */
	    /* fprintf(stderr, "."); fflush(stderr);         */

            if( FD_ISSET(can_fd, &rfds) ) {
            	/* it was the CAN fd */

/* got=read(can_fd, rx , 80 ); */
/* Stringpuffer für die TCPIP Ausgabe umfasst nur ca. 2000 Zeichen
 * 20 Zeilen x 70 Zeichen == 1400 Zeichen.
 * Nun sollte der Puffer nicht mehr überlaufen 
 */
 
/* got=read(can_fd, rx , 20 ); */
/* CAN-REport bekommt zerstückelte Zeilen und verkraftet dies nicht */

	    got=read(can_fd, rx , 20 );
	    if( got > 0) {
		/* Messages in read */
		if (debug) {
		    fprintf(stderr, "--------------\n");
		    fprintf(stderr, "Received got=%d\n", got);
		} 
		prx = &rx[0];
		/* for all received messages */
		for(i = 0; i < got; i++) {
		    if((rx[i].id < 0) || (filter(rx[i].id) == TRUE)) { 
			/* for all received messages */
			/* show_message(&rx[i]); */
/* prx muß auch bei False erhöht werden */
/* show_message() könnte zuviele Nachrichten nach 'send_line' schreiben */
			show_message(prx);
		    } 
		    prx++; /* nächste Nachricht */
		}


#if 0		
		if(send_line_cnt > 1500) 
#endif		
		{
		    /* formatted string reaches Buffer end !*/
		    j = display_line(send_line);
		    if (j == -1) {
		        if (debug) {
		            fprintf(stderr,"Error (display_line): %s\n",
		            		strerror(errno));
		        }    
		    }	
		    reset_send_line();
		    if(j == -1) {
			established = 0;
			break;
		    }
		}

	    } else {
	        /* read returned with error */
		fprintf(stderr, "- Received got = %d\n", got);
		fflush(stderr);
	    }
	    } /* it was the CAN fd */

            if( FD_ISSET(server_fd, &rfds) ) {
            	/* it was the stdio terminal fd */
            	/* Lines are coming here with \r\n */
            	rcnt = read(server_fd , in_line, MAXLINE);
		BDEBUG("%d new commands\n", rcnt);
		if(rcnt == -1) {
		    fprintf(stderr, "Error reading from socket %d\n", errno);
		    established = 0;
		} else {
/************************************************************************/
/* 
* select() kehrt für server_fd zurück, 
* obwohl der Client die Verbindung gelöst hat.
* rcnt ist immer 0 und die Schleife läuft endlos mit 100% CPU last.
*	select_flag soll diese Situation erkennen
*	Ursache unbekannt
*/
		    if (rcnt == 0) {
			select_flag++;  /* Test */
			if (select_flag > 50) {
			    established = 0;
			    fprintf(stderr, "Problem with TCP/IP connection\n");
			}
		    } else {
			select_flag = 0; /* Test */
		    }
/************************************************************************/

		    for(i = 0; i < rcnt; i++) {
			/* read input chars from recv buffer */
			if(change_format(in_line[i]) == -1) {
			    established = 0;
			}
		    }
		}
	    } /* Server-in/stdio fd */

	}
    }	/* while(established)  */
}
/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
        fprintf(stderr, "Horch Server: close connection\n");
	if(close(server_fd) < 0) {
	    fprintf(stderr, "   socket close failed: %d\n", errno);
	}

    } /* for(; ; ;) */

   /************************************/
   /* Shutdown server, should not happen */
   /************************************/

TCP_SERVER_DONE:

    BDEBUG("TCPserver: Closing listening socket\n");
    /* if(socketClose(asd) < 0) { */
    if(close(server_fd) < 0) {
	 printf("TCPserver: Socket close failed %d\n", errno);
    }
    return 0;

}
 void MainWindow::setConstraintValues( Constraint* constraint, const int motor_index,
         const eConstraintChange change, const double value ) {
     btRotationalLimitMotor* motor = constraint->getConstraint()->getRotationalLimitMotor(motor_index);
     switch (change) {
         case CC_ERP:
             motor->m_ERP = value;
             break;
         case CC_ACCUMULATED_IMPULSE:
             motor->m_accumulatedImpulse = value;
             break;
         case CC_BOUNCE:
             motor->m_bounce = value;
             break;
         case CC_CURRENT_LIMIT:
             motor->m_currentLimit = value;
             break;
         case CC_CURRENT_LIMIT_ERROR:
             motor->m_currentLimitError = value;
             break;
         case CC_DAMPING:
             motor->m_damping = value;
             break;
         case CC_HI_LIMIT:
             motor->m_hiLimit = value;
             break;
         case CC_LIMIT_SOFTNESS:
             motor->m_limitSoftness = value;
             break;
         case CC_LO_LIMIT:
             motor->m_loLimit = value;
             break;
         case CC_MAX_LIMIT_FORCE:
             motor->m_maxLimitForce = value;
             break;
         case CC_MAX_MOTOR_FORCE:
             motor->m_maxMotorForce = value;
             break;
         case CC_TARGET_VELOCITY:
             motor->m_targetVelocity = value;
             break;
         case CC_ENABLE:
             motor->m_enableMotor = bool(value);
             break;
         case CC_LOWER_ANGULAR_LIMIT_X:
         case CC_LOWER_ANGULAR_LIMIT_Y:
         case CC_LOWER_ANGULAR_LIMIT_Z:
         {
             btVector3 limit = constraint->getAngularLowerLimits();
             switch (change) {
                 case CC_LOWER_ANGULAR_LIMIT_X:limit.setX(value);
                     break;
                 case CC_LOWER_ANGULAR_LIMIT_Y:limit.setY(value);
                     break;
                 case CC_LOWER_ANGULAR_LIMIT_Z:limit.setZ(value);
                     break;
                 default: BDEBUG(TO_STRING(change));
                     assert(0);
             }
             constraint->setAngularLowerLimits(limit);
             constraint->getConstraint()->setAngularLowerLimit(limit);
             break;
         }
         case CC_UPPER_ANGULAR_LIMIT_X:
         case CC_UPPER_ANGULAR_LIMIT_Y:
         case CC_UPPER_ANGULAR_LIMIT_Z:
         {
             btVector3 limit = constraint->getAngularUpperLimits();
             switch (change) {
                 case CC_UPPER_ANGULAR_LIMIT_X:limit.setX(value);
                     break;
                 case CC_UPPER_ANGULAR_LIMIT_Y:limit.setY(value);
                     break;
                 case CC_UPPER_ANGULAR_LIMIT_Z:limit.setZ(value);
                     break;
                 default: BDEBUG(TO_STRING(change));
                     assert(0);
             }
             constraint->setAngularUpperLimits(limit);
             constraint->getConstraint()->setAngularUpperLimit(limit);
             break;
         }
     }
 }
    void MainWindow::applyForce( eForceType type ) {
        bool play = getSimulationThread().getSimulator().isPlaying();
        if (play) {
            pause();
        }
        getSimulationThread().wait();
        getSimulationThread().getSimulator().getLock().lockForRead();
        Creature* creature = getSimulationThread().getSimulator().currentCreature();
        if (creature) {

            if (type == FT_NONE) {
                for (int i = 0; i < creature->getNumberOfBodyParts(); ++i) {
                    creature->getBodyPart(i).getRigidBody()->clearForces();
                }
                getUiInspector().sbx_force_x->setValue(0.0);
                getUiInspector().sbx_force_y->setValue(0.0);
                getUiInspector().sbx_force_z->setValue(0.0);
            } else {
                std::vector<btRigidBody*>& bodies = getRendererThread().getRenderer().getSelectedBodyParts();
                btVector3 forces(getUiInspector().sbx_force_x->value(),
                        getUiInspector().sbx_force_y->value(),
                        getUiInspector().sbx_force_z->value());

                for (std::vector<btRigidBody*>::iterator it = bodies.begin();
                        it != bodies.end(); ++it) {
                    btRigidBody* rigid_body = *it;
                    BodyPart* body = NULL;
                    for (int i = 0; i < creature->getNumberOfBodyParts(); ++i) {
                        if (creature->getBodyPart(i).getRigidBody() == rigid_body) {
                            body = &creature->getBodyPart(i);
                            break;
                        }
                    }
                    assert(body);
                    rigid_body->activate(true);
                    switch (type) {
                        case FT_CENTRAL_FORCE: rigid_body->applyCentralForce(forces);
                            break;
                        case FT_CENTRAL_TORQUE: rigid_body->applyTorque(forces);
                            break;
                        case FT_IMPULSE_FORCE: rigid_body->applyCentralImpulse(forces);
                            break;
                        case FT_IMPULSE_TORQUE: rigid_body->applyTorqueImpulse(forces);
                            break;
                        case FT_RELATIVE_FORCE:
                            break;
                        case FT_RELATIVE_IMPULSE:
                            rigid_body->applyImpulse(forces, btVector3(0, -body->getSizeY() / 2.0, 0));
                            break;
                        case FT_EACH_STEP:
//                            creature->setTmpValueX(forces.x());
//                            creature->setTmpValueY(forces.y());
//                            creature->setTmpValueZ(forces.z());
                            break;
                        default:
                            BDEBUG(TO_STRING(type));
                            assert(0);
                    }
                }
            }

        }
        getSimulationThread().getSimulator().getLock().unlock();
        if (play) {
            this->play();
        }
    }
 void MainWindow::setCreatureImpulse( double value ) {
     Creature* creature = getSimulationThread().getSimulator().currentCreature();
     if (creature) {
         BDEBUG("setting impulse: " + TO_STRING(value));
     }
 }