IMP::display::Geometries RestraintGeometry::get_components() const { IMP_CHECK_OBJECT(r_); base::Pointer<kernel::Restraint> rd = r_->create_current_decomposition(); if (!rd) return IMP::display::Geometries(); kernel::RestraintSet *rs = dynamic_cast<kernel::RestraintSet *>(rd.get()); rd->set_was_used(true); IMP::display::Geometries ret; if (!rs) { kernel::ParticlesTemp ps = IMP::get_input_particles(r_->get_inputs()); r_->set_was_used(true); for (unsigned int i = 0; i < ps.size(); ++i) { if (!get_has_coordinates(ps[i])) continue; for (unsigned int j = 0; j < i; ++j) { if (!get_has_coordinates(ps[j])) continue; ret.push_back(new SegmentGeometry(algebra::Segment3D( get_coordinates(ps[i]), get_coordinates(ps[j])))); } } } else { for (unsigned int i = 0; i < rs->get_number_of_restraints(); ++i) { kernel::Restraint *rc = rs->get_restraint(i); rc->set_was_used(true); ret.push_back(new RestraintGeometry(rc, m_)); } } return ret; }
void Shmenu_window::draw_hexagon() { get_coordinates(); shapes.push_back(new Regular_polygon(Point(x,y),6,100)); attach(shapes[shapes.size()-1]); redraw(); }
void Shmenu_window::draw_circle() { get_coordinates(); shapes.push_back(new Circle(Point(x,y),100)); attach(shapes[shapes.size()-1]); redraw(); }
static PyObject *mmeval_elecenergy(PyObject *self, PyObject *args) { // Get the AmberSystem PyObject *mol; if(!PyArg_ParseTuple(args, "O", &mol)) return NULL; int charge_size = 0; float *charge = get_block_as_float_array(mol, "CHARGE", &charge_size); if(charge == NULL) { fprintf(stderr, "Error: Couldn't find CHARGE block.\n"); return NULL; } // Extract coordinate arrays float *x, *y, *z; int num_atoms = get_coordinates(mol, &x, &y, &z); float Eelec = calc_elec_energy(charge, x, y, z, num_atoms); free(x); free(y); free(z); return Py_BuildValue("f", Eelec); }
IMPCORE_BEGIN_NAMESPACE void XYZ::show(std::ostream &out) const { out << "(" <<algebra::commas_io(get_coordinates())<<")"; }
static void get_volume_onoff_coordinates(int &x1, int &y1, int &x2, int &y2){ get_coordinates(x1,y1,x2,y2); x1 = x2-button_width-1; //y1 = 0; y2 = y1 + button_width-3; }
static void create_marker (EogImage *image, EogMapPlugin *plugin) { gdouble lon, lat; if (!image) return; if (!eog_image_has_data (image, EOG_IMAGE_DATA_EXIF) && !eog_image_load (image, EOG_IMAGE_DATA_EXIF, NULL, NULL)) return; if (get_coordinates (image, &lat, &lon)) { ChamplainLabel *marker; marker = CHAMPLAIN_LABEL (champlain_label_new ()); champlain_label_set_draw_background (CHAMPLAIN_LABEL (marker), FALSE); update_marker_image (marker, GTK_ICON_SIZE_MENU); g_object_set_data_full (G_OBJECT (image), "marker", marker, (GDestroyNotify) clutter_actor_destroy); g_object_set_data (G_OBJECT (marker), "image", image); champlain_location_set_location (CHAMPLAIN_LOCATION (marker), lat, lon); champlain_marker_layer_add_marker (plugin->layer, CHAMPLAIN_MARKER (marker)); g_signal_connect (marker, "button-release-event", G_CALLBACK (change_image), plugin); } }
void Mvshape_window::next() { if (shapes.size()==0) error("No shapes available"); get_coordinates(); int dx = x - shapes[shapes.size()-1].point(0).x; int dy = y - shapes[shapes.size()-1].point(0).y; shapes[shapes.size()-1].move(dx,dy); redraw(); }
std::string Breakpoint::to_string() { std::stringstream ss; if (positions.support.size() > 1) { ss << "\t\tTREE: "; ss << TRANS_type(this->get_SVtype()); ss << " "; ss << get_coordinates().start.min_pos; ss << ":"; ss << get_coordinates().stop.max_pos; ss << " "; ss << this->length; ss << " "; ss << positions.support.size(); ss << " "; ss << get_strand(2); } return ss.str(); }
DeltaDistributionFunction::DeltaDistributionFunction( const Particles& particles, double max_distance, double bin_size) : Distribution<algebra::Vector3D>(bin_size) { get_coordinates(particles, coordinates_); get_form_factors(particles, get_default_form_factor_table(), form_factors_, HEAVY_ATOMS); // compute max distance if not given max_distance_ = max_distance; if (max_distance_ <= 0.0) max_distance_ = compute_max_distance(particles); }
static void get_name_coordinates(int &x1, int &y1, int &x2, int &y2){ get_coordinates(x1,y1,x2,y2); //get_slider2_coordinates(x1,y1,x2,y2); x1 += 2; x2 = x2-button_width-3; y1 = y2-name_height; // y1+=slider_height; // y2+=name_height; }
std::string Breakpoint::to_string(RefVector ref) { std::stringstream ss; ss << "("; ss << get_chr(get_coordinates().start.min_pos, ref); ss << ":"; ss << calc_pos(get_coordinates().start.min_pos, ref); ss << "-"; ss << get_chr(get_coordinates().stop.max_pos, ref); ss << ":"; ss << calc_pos(get_coordinates().stop.max_pos, ref); ss << " "; ss << positions.support.size(); ss << " "; ss << this->sv_debug; ss << " "; ss << this->get_strand(2); ss << "\n"; int num = 0; for (std::map<std::string, read_str>::iterator i = positions.support.begin(); i != positions.support.end() && num < Parameter::Instance()->report_n_reads; i++) { ss << "\t"; ss << (*i).first; ss << " "; ss << (*i).second.type; if ((*i).second.strand.first) { ss << "+"; } else { ss << "-"; } if ((*i).second.strand.second) { ss << "+"; } else { ss << "-"; } num++; ss << "\n"; } ss << " "; return ss.str(); }
void ResidueRotamer::set_coordinates(unsigned index, IMP::atom::Residue &rd) const { IMP_USAGE_CHECK(index < size_, "no rotamer at given index"); IMP_USAGE_CHECK(rd.get_residue_type() == residue_type_, "wrong residue type"); IMP::atom::Hierarchies mhs = IMP::atom::get_by_type(rd, IMP::atom::ATOM_TYPE); for (size_t i = 0; i != mhs.size(); ++i) { IMP::atom::Atom at = mhs[i].get_as_atom(); IMP::atom::AtomType at_t = at.get_atom_type(); if (get_atom_exists(at_t)) { const IMP::algebra::Vector3D &coords = get_coordinates(index, at_t); IMP::core::XYZ(at).set_coordinates(coords); } } }
void HierarchyLoadXYZs::setup_particle( RMF::NodeConstHandle n, Model *m, ParticleIndex p, const ParticleIndexes &rigid_bodies) { if (!ip_factory_.get_is(n)) return; if (!core::XYZ::get_is_setup(m, p)) core::XYZ::setup_particle(m, p); /* If there is a rigid body parent set up, add this particle as a child (unless it's an old-style rigid body, in which case this has been done already) */ if (!rigid_bodies.empty() && !(rigid_bodies.size()==1 && rigid_bodies.back() == p) && !n.get_has_value(rb_index_key_)) { core::RigidBody rb(m, rigid_bodies.back()); /* For nested rigid bodies, this XYZ particle is *also* the rigid body. So don't make ourselves our own child - add to the parent rigid body instead. */ if (rigid_bodies.back() == p) { IMP_INTERNAL_CHECK(rigid_bodies.size() >= 2, "Nested rigid body " << m->get_particle_name(p) << " but could not find parent rigid body"); rb = core::RigidBody(m, rigid_bodies[rigid_bodies.size() - 2]); } rb.add_member(p); if (reference_frame_factory_.get_is(n) && !reference_frame_factory_.get_is_static(n)) { IMP_LOG_VERBOSE("Member particle " << m->get_particle_name(p) << " is not static and is also a rigid body" << std::endl); rb.set_is_rigid_member(p, false); } else if (!ip_factory_.get_is_static(n)) { IMP_LOG_VERBOSE("Member particle " << m->get_particle_name(p) << " is not static" << std::endl); rb.set_is_rigid_member(p, false); } else { IMP_LOG_VERBOSE("Member particle " << m->get_particle_name(p) << " is static" << std::endl); rb.set_is_rigid_member(p, true); core::RigidBodyMember(m, p) .set_internal_coordinates(get_coordinates(n, ip_factory_)); } } link_particle(n, m, p, rigid_bodies); }
/** \param[in] acc If true (not nullptr), partial first derivatives should be calculated. \return score associated with this restraint for the given state of the model. */ double RadiusOfGyrationRestraint::unprotected_evaluate( DerivativeAccumulator *acc) const { IMP_LOG_TERSE( "SAXS RadiusOfGyrationRestraint::evaluate score\n"); //get centroid algebra::Vector3D centroid(0.0, 0.0, 0.0); std::vector<algebra::Vector3D> coordinates(particles_.size()); get_coordinates(particles_, coordinates); for (unsigned int i = 0; i < particles_.size(); i++) { centroid += coordinates[i]; } centroid /= particles_.size(); double radg = 0; for (unsigned int i = 0; i < particles_.size(); i++) { radg += get_squared_distance(coordinates[i], centroid); } radg /= particles_.size(); radg = sqrt(radg); double score = (radg - exp_rg_)/exp_rg_; //TODO: improve bool calc_deriv = acc? true: false; if(!calc_deriv) return score; IMP_LOG_TERSE( "SAXS RadiusOfGyrationRestraint::compute derivatives\n"); const FloatKeys keys = IMP::core::XYZ::get_xyz_keys(); double factor = 1.0/(particles_.size()*radg); for (unsigned int i = 0; i < particles_.size(); i++) { IMP::algebra::Vector3D derivative = (coordinates[i]-centroid)*factor; for (int j = 0; j < 3; j++) { particles_[i]->add_to_derivative(keys[j],derivative[j],*acc); } } IMP_LOG_TERSE( "SAXS RadiusOfGyrationRestraint::done derivatives, score " << score << "\n"); return score; }
BootloaderHandleMessageResponse handle_message(const void *message, void *response) { switch(tfp_get_fid_from_message(message)) { case FID_GET_COORDINATES: return get_coordinates(message, response); case FID_GET_STATUS: return get_status(message, response); case FID_GET_ALTITUDE: return get_altitude(message, response); case FID_GET_MOTION: return get_motion(message, response); case FID_GET_DATE_TIME: return get_date_time(message, response); case FID_RESTART: return restart(message); case FID_SET_COORDINATES_CALLBACK_PERIOD: return set_coordinates_callback_period(message); case FID_GET_COORDINATES_CALLBACK_PERIOD: return get_coordinates_callback_period(message, response); case FID_SET_STATUS_CALLBACK_PERIOD: return set_status_callback_period(message); case FID_GET_STATUS_CALLBACK_PERIOD: return get_status_callback_period(message, response); case FID_SET_ALTITUDE_CALLBACK_PERIOD: return set_altitude_callback_period(message); case FID_GET_ALTITUDE_CALLBACK_PERIOD: return get_altitude_callback_period(message, response); case FID_SET_MOTION_CALLBACK_PERIOD: return set_motion_callback_period(message); case FID_GET_MOTION_CALLBACK_PERIOD: return get_motion_callback_period(message, response); case FID_SET_DATE_TIME_CALLBACK_PERIOD: return set_date_time_callback_period(message); case FID_GET_DATE_TIME_CALLBACK_PERIOD: return get_date_time_callback_period(message, response); default: return HANDLE_MESSAGE_RESPONSE_NOT_SUPPORTED; } }
/** * Calculates the bond energy of an AmberSystem. */ static PyObject *mmeval_bondenergy(PyObject *self, PyObject *args) { // Get the AmberSystem PyObject *mol; if(!PyArg_ParseTuple(args, "O", &mol)) return NULL; int bond_l0_size = 0, bond_k_size = 0; float *bond_l0 = get_block_as_float_array(mol, "BOND_EQUIL_VALUE", &bond_l0_size); float *bond_k = get_block_as_float_array(mol, "BOND_FORCE_CONSTANT", &bond_k_size); if(bond_l0_size != bond_k_size) { fprintf(stderr, "Error: Size of BOND_EQUIL_VALUE and BOND_FORCE_CONSTANT blocks is not the same.\n"); return NULL; } // Extract coordinate arrays float *x, *y, *z; int num_atoms = get_coordinates(mol, &x, &y, &z); int bond_list_size = 0; int *bond_list = get_block_as_int_array(mol, "BONDS_INC_HYDROGEN", &bond_list_size); float Ebond_h = calc_bond_energy(bond_list, bond_l0, bond_k, x, y, z, num_atoms, bond_list_size, bond_l0_size); free(bond_list); bond_list = get_block_as_int_array(mol, "BONDS_WITHOUT_HYDROGEN", &bond_list_size); float Ebond_nonh = calc_bond_energy(bond_list, bond_l0, bond_k, x, y, z, num_atoms, bond_list_size, bond_l0_size); free(bond_list); free(x); free(y); free(z); return Py_BuildValue("f", Ebond_h + Ebond_nonh); }
static void get_effects_onoff_coordinates(int &x1, int &y1, int &x2, int &y2){ get_coordinates(x1,y1,x2,y2); x1 = x2-button_width-1; y1 = y2-button_width+2; }
void process_commands() { unsigned long codenum; //throw away variable if (code_seen('N')) { gcode_N = code_value_long(); if (gcode_N != gcode_LastN+1 && (strstr(cmdbuffer, "M110") == NULL) ) { gcode_LastN=0; pc.printf("ok"); //if(gcode_N != gcode_LastN+1 && !code_seen("M110") ) { //Hmm, compile size is different between using this vs the line above even though it should be the same thing. Keeping old method. //pc.printf("Serial Error: Line Number is not Last Line Number+1, Last Line:"); //pc.printf("%d\n",gcode_LastN); //FlushSerialRequestResend(); return; } if (code_seen('*')) { int checksum = 0; int count=0; while (cmdbuffer[count] != '*') checksum = checksum^cmdbuffer[count++]; if ( (int)code_value() != checksum) { //pc.printf("Error: checksum mismatch, Last Line:"); //pc.printf("%d\n",gcode_LastN); //FlushSerialRequestResend(); return; } //if no errors, continue parsing } else { //pc.printf("Error: No Checksum with line number, Last Line:"); //pc.printf("%d\n",gcode_LastN); //FlushSerialRequestResend(); return; } gcode_LastN = gcode_N; //if no errors, continue parsing } else { // if we don't receive 'N' but still see '*' if (code_seen('*')) { //pc.printf("Error: No Line Number with checksum, Last Line:"); //pc.printf("%d\n",gcode_LastN); return; } } //continues parsing only if we don't receive any 'N' or '*' or no errors if we do. :) if (code_seen('G')) { switch ((int)code_value()) { case 0: // G0 -> G1 case 1: // G1 reset_timers();//avoid timer overflow after 30 seconds get_coordinates(); // For X Y Z E F x_steps_to_take = abs(destination_x - current_x)*x_steps_per_unit; y_steps_to_take = abs(destination_y - current_y)*y_steps_per_unit; z_steps_to_take = abs(destination_z - current_z)*z_steps_per_unit; e_steps_to_take = abs(destination_e - current_e)*e_steps_per_unit; //printf(" x_steps_to_take:%d\n", x_steps_to_take); time_for_move = max(X_TIME_FOR_MOVE,Y_TIME_FOR_MOVE); time_for_move = max(time_for_move,Z_TIME_FOR_MOVE); time_for_move = max(time_for_move,E_TIME_FOR_MOVE); if (x_steps_to_take) x_interval = time_for_move/x_steps_to_take; if (y_steps_to_take) y_interval = time_for_move/y_steps_to_take; if (z_steps_to_take) z_interval = time_for_move/z_steps_to_take; if (e_steps_to_take) e_interval = time_for_move/e_steps_to_take; x_steps_remaining = x_steps_to_take; y_steps_remaining = y_steps_to_take; z_steps_remaining = z_steps_to_take; e_steps_remaining = e_steps_to_take; if (DEBUGGING) { pc.printf("destination_x: %f\n",destination_x); pc.printf("current_x: %f\n",current_x); pc.printf("x_steps_to_take: %d\n",x_steps_to_take); pc.printf("X_TIME_FOR_MOVE: %f\n",X_TIME_FOR_MOVE); pc.printf("x_interval: %f\n\n",x_interval); pc.printf("destination_y: %f\n",destination_y); pc.printf("current_y: %f\n",current_y); pc.printf("y_steps_to_take: %d\n",y_steps_to_take); pc.printf("Y_TIME_FOR_MOVE: %f\n",Y_TIME_FOR_MOVE); pc.printf("y_interval: %f\n\n",y_interval); pc.printf("destination_z: %f\n",destination_z); pc.printf("current_z: %f\n",current_z); pc.printf("z_steps_to_take: %d\n",z_steps_to_take); pc.printf("Z_TIME_FOR_MOVE: %f\n",Z_TIME_FOR_MOVE); pc.printf("z_interval: %f\n\n",z_interval); pc.printf("destination_e: %f\n",destination_e); pc.printf("current_e: %f\n",current_e); pc.printf("e_steps_to_take: %d\n",e_steps_to_take); pc.printf("E_TIME_FOR_MOVE: %f\n",E_TIME_FOR_MOVE); pc.printf("e_interval: %f\n\n",e_interval); } linear_move(); // make the move ClearToSend(); return; case 4: // G4 dwell codenum = 0; if (code_seen('P')) codenum = code_value(); // milliseconds to wait if (code_seen('S')) codenum = code_value()*1000; // seconds to wait previous_millis_heater = millis(); // keep track of when we started waiting while ((millis() - previous_millis_heater) < codenum ) manage_heater(); //manage heater until time is up break; case 90: // G90 relative_mode = false; break; case 91: // G91 relative_mode = true; break; case 92: // G92 if (code_seen('X')) current_x = code_value(); if (code_seen('Y')) current_y = code_value(); if (code_seen('Z')) current_z = code_value(); if (code_seen('E')) current_e = code_value(); break; case 93: // G93 pc.printf("previous_micros:%d\n", previous_micros); pc.printf("previous_micros_x:%d\n", previous_micros_x); pc.printf("previous_micros_y:%d\n", previous_micros_y); pc.printf("previous_micros_z:%d\n", previous_micros_z); break; } } if (code_seen('M')) { switch ( (int)code_value() ) { case 104: // M104 - set hot-end temp if (code_seen('S')) { target_raw = temp2analog(code_value()); //pc.printf("target_raw: %d\n ", target_raw); } break; case 140: // M140 - set heated-printbed temp if (code_seen('S')) { target_raw1 = temp2analog(code_value()); //pc.printf("target_raw1: %d\n ", target_raw); } break; case 105: // M105 pc.printf("ok T:"); if (TEMP_0_PIN != NC) { pc.printf("%f\n", analog2temp( (p_temp0.read_u16()) )); } else { pc.printf("0.0\n"); } if (!code_seen('N')) return; // If M105 is sent from generated gcode, then it needs a response. break; case 109: // M109 - Wait for heater to reach target. if (code_seen('S')) target_raw = temp2analog(code_value()); previous_millis_heater = millis(); while (current_raw < target_raw) { if ( (millis()-previous_millis_heater) > 1000 ) { //Print Temp Reading every 1 second while heating up. pc.printf("ok T:"); if (TEMP_0_PIN != NC) { pc.printf("%f\n", analog2temp(p_temp0.read_u16())); } else { pc.printf("0.0\n"); } previous_millis_heater = millis(); } manage_heater(); } break; case 106: //M106 Fan On p_fan = 1; break; case 107: //M107 Fan Off p_fan = 0; break; case 80: // M81 - ATX Power On //if(PS_ON_PIN > -1) pinMode(PS_ON_PIN,OUTPUT); //GND break; case 81: // M81 - ATX Power Off //if(PS_ON_PIN > -1) pinMode(PS_ON_PIN,INPUT); //Floating break; case 82: relative_mode_e = false; break; case 83: relative_mode_e = true; break; case 84: disable_x(); disable_y(); disable_z(); disable_e(); break; case 85: // M85 code_seen('S'); max_inactive_time = code_value()*1000; break; case 86: // M86 If Endstop is Not Activated then Abort Print if (code_seen('X')) { if (X_MIN_PIN != NC) { if ( p_X_min == ENDSTOPS_INVERTING ) { kill(3); } } } if (code_seen('Y')) { if (Y_MIN_PIN != NC) { if ( p_Y_min == ENDSTOPS_INVERTING ) { kill(4); } } } break; case 92: // M92 if (code_seen('X')) x_steps_per_unit = code_value(); if (code_seen('Y')) y_steps_per_unit = code_value(); if (code_seen('Z')) z_steps_per_unit = code_value(); if (code_seen('E')) e_steps_per_unit = code_value(); break; } } ClearToSend(); }
/** \brief Execute the command stored in com. */ void process_command(GCode *com) { unsigned long codenum; //throw away variable #ifdef INCLUDE_DEBUG_COMMUNICATION if(DEBUG_COMMUNICATION) { if(GCODE_HAS_G(com) || (GCODE_HAS_M(com) && com->M!=111)) { gcode_command_finished(); // free command cache previous_millis_cmd = millis(); return; } } #endif if(GCODE_HAS_G(com)) { switch(com->G) { case 0: // G0 -> G1 case 1: // G1 if(get_coordinates(com)) // For X Y Z E F queue_move(ALWAYS_CHECK_ENDSTOPS); break; case 4: // G4 dwell codenum = 0; if(GCODE_HAS_P(com)) codenum = com->P; // milliseconds to wait if(GCODE_HAS_S(com)) codenum = (long)com->S * 1000; // seconds to wait codenum += millis(); // keep track of when we started waiting while(millis() < codenum ) { gcode_read_serial(); manage_temperatures(false); } break; case 20: // Units to inches unit_inches = 1; break; case 21: // Units to mm unit_inches = 0; break; case 28: {//G28 Home all Axis one at a time wait_until_end_of_move(); float saved_feedrate = printer_state.feedrate; for(byte i=0; i < 4; i++) { printer_state.destinationSteps[i] = printer_state.currentPositionSteps[i]; } byte home_all_axis = !(GCODE_HAS_X(com) || GCODE_HAS_Y(com) || GCODE_HAS_Z(com)); if(home_all_axis || GCODE_HAS_X(com)) { if ((X_MIN_PIN > -1 && X_HOME_DIR==-1) || (X_MAX_PIN > -1 && X_HOME_DIR==1)) { printer_state.destinationSteps[0] = 1.5 * printer_state.xMaxSteps * X_HOME_DIR; printer_state.currentPositionSteps[0] = -printer_state.destinationSteps[0]; printer_state.feedrate = homing_feedrate[0]; queue_move(true); wait_until_end_of_move(); printer_state.currentPositionSteps[0] = 0; printer_state.destinationSteps[0] = axis_steps_per_unit[0]*-5 * X_HOME_DIR; queue_move(true); wait_until_end_of_move(); printer_state.destinationSteps[0] = axis_steps_per_unit[0]*10 * X_HOME_DIR; queue_move(true); wait_until_end_of_move(); printer_state.currentPositionSteps[0] = (X_HOME_DIR == -1) ? 0 : printer_state.xMaxSteps; printer_state.destinationSteps[0] = printer_state.currentPositionSteps[0]; } } if(home_all_axis || GCODE_HAS_Y(com)) { if ((Y_MIN_PIN > -1 && Y_HOME_DIR==-1) || (Y_MAX_PIN > -1 && Y_HOME_DIR==1)) { printer_state.currentPositionSteps[1] = 0; printer_state.destinationSteps[1] = 1.5 * printer_state.yMaxSteps * Y_HOME_DIR; printer_state.currentPositionSteps[1] = -printer_state.destinationSteps[1]; printer_state.feedrate = homing_feedrate[1]; queue_move(true); wait_until_end_of_move(); printer_state.currentPositionSteps[1] = 0; printer_state.destinationSteps[1] = axis_steps_per_unit[1]*-5 * Y_HOME_DIR; queue_move(true); wait_until_end_of_move(); printer_state.destinationSteps[1] = axis_steps_per_unit[1]*10 * Y_HOME_DIR; queue_move(true); wait_until_end_of_move(); printer_state.currentPositionSteps[1] = (Y_HOME_DIR == -1) ? 0 : printer_state.yMaxSteps; printer_state.destinationSteps[1] = printer_state.currentPositionSteps[1]; } } if(home_all_axis || GCODE_HAS_Z(com)) { if ((Z_MIN_PIN > -1 && Z_HOME_DIR==-1) || (Z_MAX_PIN > -1 && Z_HOME_DIR==1)) { printer_state.currentPositionSteps[2] = 0; printer_state.destinationSteps[2] = 1.5 * printer_state.zMaxSteps * Z_HOME_DIR; printer_state.currentPositionSteps[2] = -printer_state.destinationSteps[2]; printer_state.feedrate = homing_feedrate[2]; queue_move(true); wait_until_end_of_move(); printer_state.currentPositionSteps[2] = 0; printer_state.destinationSteps[2] = axis_steps_per_unit[2]*-2 * Z_HOME_DIR; queue_move(true); wait_until_end_of_move(); printer_state.destinationSteps[2] = axis_steps_per_unit[2]*10 * Z_HOME_DIR; queue_move(true); wait_until_end_of_move(); printer_state.currentPositionSteps[2] = (Z_HOME_DIR == -1) ? 0 : printer_state.zMaxSteps; printer_state.destinationSteps[2] = printer_state.currentPositionSteps[2]; } } printer_state.feedrate = saved_feedrate; } break; case 90: // G90 relative_mode = false; break; case 91: // G91 relative_mode = true; break; case 92: // G92 if(GCODE_HAS_X(com)) printer_state.currentPositionSteps[0] = com->X*axis_steps_per_unit[0]*(unit_inches?25.4:1.0)-printer_state.offsetX; if(GCODE_HAS_Y(com)) printer_state.currentPositionSteps[1] = com->Y*axis_steps_per_unit[1]*(unit_inches?25.4:1.0)-printer_state.offsetY; if(GCODE_HAS_Z(com)) printer_state.currentPositionSteps[2] = com->Z*axis_steps_per_unit[2]*(unit_inches?25.4:1.0); if(GCODE_HAS_E(com)) { printer_state.currentPositionSteps[3] = com->E*axis_steps_per_unit[3]*(unit_inches?25.4:1.0); } break; } previous_millis_cmd = millis(); } else if(GCODE_HAS_M(com)) { // Process M Code switch( com->M ) { #ifdef SDSUPPORT case 20: // M20 - list SD card out.println_P(PSTR("Begin file list")); root.ls(); out.println_P(PSTR("End file list")); break; case 21: // M21 - init SD card sdmode = false; initsd(); break; case 22: //M22 - release SD card sdmode = false; sdactive = false; break; case 23: //M23 - Select file if(sdactive) { sdmode = false; file.close(); if (file.open(&root, com->text, O_READ)) { out.print_P(PSTR("File opened:")); out.print(com->text); out.print_P(PSTR(" Size:")); out.println(file.fileSize()); sdpos = 0; filesize = file.fileSize(); out.println_P(PSTR("File selected")); } else { out.println_P(PSTR("file.open failed")); } } break; case 24: //M24 - Start SD print if(sdactive) { sdmode = true; } break; case 25: //M25 - Pause SD print if(sdmode) { sdmode = false; } break; case 26: //M26 - Set SD index if(sdactive && GCODE_HAS_S(com)) { sdpos = com->S; file.seekSet(sdpos); } break; case 27: //M27 - Get SD status if(sdactive) { out.print_P(PSTR("SD printing byte ")); out.print(sdpos); out.print("/"); out.println(filesize); } else { out.println_P(PSTR("Not SD printing")); } break; case 28: //M28 - Start SD write if(sdactive) { char* npos = 0; file.close(); sdmode = false; if (!file.open(&root,com->text, O_CREAT | O_APPEND | O_WRITE | O_TRUNC)) { out.print_P(PSTR("open failed, File: ")); out.print(com->text); out.print_P(PSTR(".")); } else { savetosd = true; out.print_P(PSTR("Writing to file: ")); out.println(com->text); } } break; case 29: //M29 - Stop SD write //processed in write to file routine above //savetosd = false; break; case 30: // M30 filename - Delete file if(sdactive) { sdmode = false; file.close(); if(SdFile::remove(&root, com->text)) { out.println_P(PSTR("File deleted")); } else { out.println_P(PSTR("Deletion failed")); } } break; #endif case 104: // M104 if(DEBUG_DRYRUN) break; wait_until_end_of_move(); if (GCODE_HAS_S(com)) extruder_set_temperature(com->S); break; case 140: // M140 set bed temp if(DEBUG_DRYRUN) break; if (GCODE_HAS_S(com)) heated_bed_set_temperature(com->S); break; case 105: // M105 get temperature. Always returns the current temperature, doesn't wait until move stopped print_temperatures(); break; case 109: // M109 - Wait for extruder heater to reach target. { if(DEBUG_DRYRUN) break; wait_until_end_of_move(); if (GCODE_HAS_S(com)) extruder_set_temperature(com->S); if(current_extruder->currentTemperatureC >= current_extruder->targetTemperature) break; codenum = millis(); long waituntil = 0; while(waituntil==0 || (waituntil!=0 && waituntil>millis())) { if( (millis() - codenum) > 1000 ) { //Print Temp Reading every 1 second while heating up. print_temperatures(); codenum = millis(); } manage_temperatures(false); gcode_read_serial(); if(waituntil==0 && current_extruder->currentTemperatureC >= current_extruder->targetTemperatureC) waituntil = millis()+1000*(long)current_extruder->watchPeriod; // now wait for temp. to stabalize } } break; case 190: // M190 - Wait bed for heater to reach target. if(DEBUG_DRYRUN) break; wait_until_end_of_move(); #if HEATED_BED_SENSOR_TYPE!=0 if (GCODE_HAS_S(com)) heated_bed_set_temperature(com->S); codenum = millis(); while(current_bed_raw < target_bed_raw) { if( (millis()-codenum) > 1000 ) { //Print Temp Reading every 1 second while heating up. print_temperatures(); codenum = millis(); } manage_temperatures(false); } #endif break; case 106: //M106 Fan On wait_until_end_of_move(); if (GCODE_HAS_S(com)) { digitalWrite(FAN_PIN, HIGH); analogWrite(FAN_PIN, constrain(com->S,0,255) ); } else digitalWrite(FAN_PIN, HIGH); break; case 107: //M107 Fan Off wait_until_end_of_move(); analogWrite(FAN_PIN, 0); digitalWrite(FAN_PIN, LOW); break; case 80: // M81 - ATX Power On wait_until_end_of_move(); if(PS_ON_PIN > -1) pinMode(PS_ON_PIN,OUTPUT); //GND break; case 81: // M81 - ATX Power Off wait_until_end_of_move(); if(PS_ON_PIN > -1) pinMode(PS_ON_PIN,INPUT); //Floating break; case 82: relative_mode_e = false; break; case 83: relative_mode_e = true; break; case 84: if(GCODE_HAS_S(com)) { stepper_inactive_time = com->S * 1000; } else { wait_until_end_of_move(); kill(true); } break; case 85: // M85 if(GCODE_HAS_S(com)) max_inactive_time = (long)com->S * 1000; else max_inactive_time = 0; break; case 92: // M92 if(GCODE_HAS_X(com)) axis_steps_per_unit[0] = com->X; if(GCODE_HAS_Y(com)) axis_steps_per_unit[1] = com->Y; if(GCODE_HAS_Z(com)) axis_steps_per_unit[2] = com->Z; if(GCODE_HAS_E(com)) current_extruder->stepsPerMM = com->E; update_ramps_parameter(); break; case 111: if(GCODE_HAS_S(com)) debug_level = com->S; if(DEBUG_DRYRUN) { // simulate movements without printing extruder_set_temperature(0); #if HEATED_BED_TYPE!=0 target_bed_raw = 0; #endif } break; case 115: // M115 out.println_P(PSTR("FIRMWARE_NAME:Repetier FIRMWARE_URL:https://github.com/repetier/Repetier-Firmware/ PROTOCOL_VERSION:1.0 MACHINE_TYPE:Mendel EXTRUDER_COUNT:1 REPETIER_PROTOCOL:1")); break; case 114: // M114 out.print_float_P(PSTR("X:"),printer_state.currentPositionSteps[0]*inv_axis_steps_per_unit[0]*(unit_inches?0.03937:1)); out.print_float_P(PSTR(" Y:"),printer_state.currentPositionSteps[1]*inv_axis_steps_per_unit[1]*(unit_inches?0.03937:1)); out.print_float_P(PSTR(" Z:"),printer_state.currentPositionSteps[2]*inv_axis_steps_per_unit[2]*(unit_inches?0.03937:1)); out.println_float_P(PSTR(" E:"),printer_state.currentPositionSteps[3]*inv_axis_steps_per_unit[3]*(unit_inches?0.03937:1)); break; case 119: // M119 wait_until_end_of_move(); #if (X_MIN_PIN > -1) out.print_P(PSTR("x_min:")); out.print_P((digitalRead(X_MIN_PIN)^ENDSTOPS_INVERTING)?PSTR("H "):PSTR("L ")); #endif #if (X_MAX_PIN > -1) out.print_P(PSTR("x_max:")); out.print_P((digitalRead(X_MAX_PIN)^ENDSTOPS_INVERTING)?PSTR("H "):PSTR("L ")); #endif #if (Y_MIN_PIN > -1) out.print_P(PSTR("y_min:")); out.print_P((digitalRead(Y_MIN_PIN)^ENDSTOPS_INVERTING)?PSTR("H "):PSTR("L ")); #endif #if (Y_MAX_PIN > -1) out.print_P(PSTR("y_max:")); out.print_P((digitalRead(Y_MAX_PIN)^ENDSTOPS_INVERTING)?PSTR("H "):PSTR("L ")); #endif #if (Z_MIN_PIN > -1) out.print_P(PSTR("z_min:")); out.print_P((digitalRead(Z_MIN_PIN)^ENDSTOPS_INVERTING)?PSTR("H "):PSTR("L ")); #endif #if (Z_MAX_PIN > -1) out.print_P(PSTR("z_max:")); out.print_P((digitalRead(Z_MAX_PIN)^ENDSTOPS_INVERTING)?PSTR("H "):PSTR("L ")); #endif out.println(); break; #ifdef RAMP_ACCELERATION case 201: // M201 if(GCODE_HAS_X(com)) axis_steps_per_sqr_second[0] = com->X * axis_steps_per_unit[0]; if(GCODE_HAS_Y(com)) axis_steps_per_sqr_second[1] = com->Y * axis_steps_per_unit[1]; if(GCODE_HAS_Z(com)) axis_steps_per_sqr_second[2] = com->Z * axis_steps_per_unit[2]; if(GCODE_HAS_E(com)) axis_steps_per_sqr_second[3] = com->E * axis_steps_per_unit[3]; break; case 202: // M202 if(GCODE_HAS_X(com)) axis_travel_steps_per_sqr_second[0] = com->X * axis_steps_per_unit[0]; if(GCODE_HAS_Y(com)) axis_travel_steps_per_sqr_second[1] = com->Y * axis_steps_per_unit[1]; if(GCODE_HAS_Z(com)) axis_travel_steps_per_sqr_second[2] = com->Z * axis_steps_per_unit[2]; if(GCODE_HAS_E(com)) axis_travel_steps_per_sqr_second[3] = com->E * axis_steps_per_unit[3]; break; #endif case 203: // M203 Temperature monitor if(GCODE_HAS_S(com)) manage_monitor = com->S; if(manage_monitor==100) manage_monitor=NUM_EXTRUDER; // Set 100 to heated bed break; case 205: // M205 Show EEPROM settings epr_output_settings(); break; case 206: // M206 T[type] P[pos] [Sint(long] [Xfloat] Set eeprom value #if EEPROM_MODE!=0 epr_update(com); #else out.println_P(PSTR("Error: No EEPROM support compiled.")); #endif break; case 222: //M222 F_CPU / S if(GCODE_HAS_S(com)) out.println_long_P(PSTR("F_CPU/x="),CPUDivU2(com->S)); break; case 223: if(GCODE_HAS_S(com)) { extruder_enable(); printer_state.extruderStepsNeeded+=(int)com->S; out.println_int_P(PSTR("Added to:"),printer_state.extruderStepsNeeded); } break; #ifdef USE_ADVANCE case 232: out.print_int_P(PSTR("Max advance="),maxadv); if(maxadv>0) out.println_float_P(PSTR(", speed="),maxadvspeed); else out.println(); maxadv=0; maxadvspeed=0; break; #endif #if USE_OPS==1 case 231: // M231 S<OPS_MODE> X<Min_Distance> Y<Retract> Z<Backslash> F<ReatrctMove> if(GCODE_HAS_S(com) && com->S>=0 && com->S<3) printer_state.opsMode = com->S; if(GCODE_HAS_X(com) && com->X>=0) printer_state.opsMinDistance = com->X; if(GCODE_HAS_Y(com) && com->Y>=0) printer_state.opsRetractDistance = com->Y; if(GCODE_HAS_Z(com) && com->Z>=-printer_state.opsRetractDistance) printer_state.opsRetractBackslash = com->Z; if(GCODE_HAS_F(com) && com->F>=0 && com->F<=100) printer_state.opsMoveAfter = com->F; extruder_select(current_extruder->id); if(printer_state.opsMode==0) { out.println_P(PSTR("OPS disabled")); } else { if(printer_state.opsMode==1) out.print_P(PSTR("OPS classic mode:")); else out.print_P(PSTR("OPS fast mode:")); out.print_float_P(PSTR("min distance = "),printer_state.opsMinDistance); out.print_float_P(PSTR(", retract = "),printer_state.opsRetractDistance); out.print_float_P(PSTR(", backslash = "),printer_state.opsRetractDistance); if(printer_state.opsMode==2) out.print_float_P(PSTR(", move after = "),printer_state.opsMoveAfter); out.println(); } #ifdef DEBUG_OPS out.println_int_P(PSTR("Timer diff"),printer_state.timer0Interval); out.println_int_P(PSTR("Ret. steps:"),printer_state.opsRetractSteps); out.println_int_P(PSTR("PushBack Steps:"),printer_state.opsPushbackSteps); out.println_int_P(PSTR("Move after steps:"),printer_state.opsMoveAfterSteps); #endif break; #endif } } else if(GCODE_HAS_T(com)) { // Process T code wait_until_end_of_move(); extruder_select(com->T); } else { if(DEBUG_ERRORS) { out.print_P(PSTR("Unknown command:")); gcode_print_command(com); out.println(); } } #ifdef ECHO_ON_EXECUTE if(DEBUG_ECHO) { out.print_P(PSTR("Echo:")); gcode_print_command(com); out.println(); } #endif gcode_command_finished(); // free command cache }
void BS_Camera::update_camera() { matrix_position = glm::vec3(get_coordinates('x'), get_coordinates('y'), get_coordinates('z')); LookAtMatrix = glm::lookAt(matrix_position, matrix_position + matrix_direction, matrix_up); }
void update_type_two_coordinate_and_velocity(int tree, int i, int centralgal) { int j, p; float tmppos; double Scale_V, dv; p=i; //printf("updating type 2 treenr =%d\n",tree); #ifdef GUO10 if(HaloGal[i].Type == 2) /* Update positions of type 2's */ #else if(Gal[i].Type == 2) /* Update positions of type 2's */ #endif { #ifdef GUO10 int snapnum = HaloGal[i].SnapNum; #else int snapnum = Gal[i].SnapNum; #endif Nids = CountIDs_snaptree[snapnum * Ntrees + tree]; OffsetIDs = OffsetIDs_snaptree[snapnum * Ntrees + tree]; size_t header_offset = 4 * sizeof(int) + 2 * TotSnaps * sizeof(int) + 2 * TotSnaps * Ntrees * sizeof(int) + 2 * sizeof(int) * NtotHalos; IdList = (long long *) (TreeAuxData + header_offset); PosList = (float *) (TreeAuxData + header_offset + TotIds * sizeof(long long)); VelList = (float *) (TreeAuxData + header_offset + TotIds * sizeof(long long) + TotIds * 3 * sizeof(float)); IdList += OffsetIDs; PosList += 3 * OffsetIDs; VelList += 3 * OffsetIDs; #ifdef GUO10 get_coordinates(HaloGal[i].Pos, HaloGal[i].Vel, HaloGal[i].MostBoundID, tree, HaloGal[i].HaloNr, HaloGal[i].SnapNum); #else get_coordinates(Gal[i].Pos, Gal[i].Vel, Gal[i].MostBoundID, tree, Gal[i].HaloNr, Gal[i].SnapNum); #endif //#ifdef SCALE_COSMOLOGY #ifdef GUO10 for(j = 0; j < 3; j++) HaloGal[i].Pos[j] *= ScalePos; #else for(j = 0; j < 3; j++) Gal[i].Pos[j] *= ScalePos; #endif //#endif #ifdef GUO10 for(j = 0; j < 3; j++) { tmppos = wrap(-HaloGal[p].MergCentralPos[j] + HaloGal[p].Pos[j],BoxSize); tmppos *= sqrt(HaloGal[p].MergTime/HaloGal[p].OriMergTime); HaloGal[p].Pos[j]=HaloGal[p].MergCentralPos[j] + tmppos; if(HaloGal[p].Pos[j] < 0) HaloGal[p].Pos[j] = BoxSize + HaloGal[p].Pos[j]; if(HaloGal[p].Pos[j] > BoxSize) HaloGal[p].Pos[j] = HaloGal[p].Pos[j] - BoxSize; } #else for(j = 0; j < 3; j++) { tmppos = wrap(-Gal[p].MergCentralPos[j] + Gal[p].Pos[j],BoxSize); #ifndef HT09_DISRUPTION tmppos *= (Gal[p].MergTime/Gal[p].OriMergTime); #else tmppos *= (Gal[p].MergRadius/Gal[p].OriMergRadius); #endif Gal[p].Pos[j]=Gal[p].MergCentralPos[j] + tmppos; if(Gal[p].Pos[j] < 0) Gal[p].Pos[j] = BoxSize + Gal[p].Pos[j]; if(Gal[p].Pos[j] > BoxSize) Gal[p].Pos[j] = Gal[p].Pos[j] - BoxSize; } #endif #ifdef GUO10 //#ifdef SCALE_COSMOLOGY //add by Qi. 06/04/2012 to account for the scale of velocity field Scale_V = scale_v_cen(Halo[HaloGal[centralgal].HaloNr].SnapNum); for (j = 0; j < 3 ; j++) { dv = HaloGal[p].Vel[j] - HaloGal[centralgal].Vel[j]/Scale_V; dv *=sqrt(ScaleMass/ScalePos) * sqrt(AA_OriginalCosm[Halo[HaloGal[centralgal].HaloNr].SnapNum]/AA[Halo[HaloGal[centralgal].HaloNr].SnapNum]); HaloGal[p].Vel[j] = HaloGal[centralgal].Vel[j] + dv; } //#endif #else Scale_V = scale_v_cen(Halo[Gal[centralgal].HaloNr].SnapNum); for (j = 0; j < 3 ; j++) { dv = Gal[p].Vel[j] - Gal[centralgal].Vel[j]/Scale_V; dv *=sqrt(ScaleMass/ScalePos) * sqrt(AA_OriginalCosm[Halo[Gal[centralgal].HaloNr].SnapNum]/AA[Halo[Gal[centralgal].HaloNr].SnapNum]); Gal[p].Vel[j] = Gal[centralgal].Vel[j] + dv; } #endif } }
int main(int argc, char* argv[]) { if(argc == 1) { printf("Usage: calculate_rmsd [options] alpha.xyz beta.xyz\n"); exit(0); } if(argc < 3) { printf ("Not enough arguments\n"); exit(EXIT_FAILURE); } bool output = false; int a = 0; int b = 0; for(int i=1; i < argc; i++) { if(strcmp(argv[i], "-o") == 0 || strcmp(argv[i], "--output") == 0) { output = true; continue; } if(a==0) { a = i; } else { b = i; } } const std::string p_file = argv[a]; const std::string q_file = argv[b]; unsigned int n_atoms {0}; std::valarray<std::string> p_atoms; std::valarray<std::string> q_atoms; matrix p_coord; matrix q_coord; std::valarray<double> p_center; std::valarray<double> q_center; std::tie(p_atoms, p_coord, n_atoms) = get_coordinates(p_file); std::tie(q_atoms, q_coord, n_atoms) = get_coordinates(q_file); // find the center of the structures p_center = kabsch::centroid(p_coord); q_center = kabsch::centroid(q_coord); // Recenter molecules in origin for(unsigned int i = 0; i < n_atoms; i++) { for(unsigned int d = 0; d < 3; d++) { p_coord[3*i + d] -= p_center[d]; q_coord[3*i + d] -= q_center[d]; } } if(output) { matrix p_rotated = kabsch::kabsch_rotate(p_coord, q_coord, n_atoms); // Center coordinates P on Q for(unsigned int i = 0; i < n_atoms; i++) { for(unsigned int d = 0; d < 3; d++) { p_rotated[3*i + d] += q_center[d]; } } // print the structure in XYZ format std::cout << n_atoms << std::endl << std::endl; print_coordinates(p_rotated, p_atoms, n_atoms); return 0; } // rotate and calculate rmsd double krmsd = kabsch::kabsch_rmsd(p_coord, q_coord, n_atoms); printf( "%.10lf \n", krmsd); } // main
static PyObject *mmeval_vdwenergy(PyObject *self, PyObject *args) { // Get the AmberSystem PyObject *mol; if(!PyArg_ParseTuple(args, "O", &mol)) return NULL; // Extract atom type and L-J parameters from the prmtop int header_size = 0; int *header = get_block_as_int_array(mol, "POINTERS", &header_size); if(header == NULL) return NULL; int nb_parm_index_size = 0; int *nb_parm_index = get_block_as_int_array(mol, "NONBONDED_PARM_INDEX", &nb_parm_index_size); if(nb_parm_index == NULL) { free(header); return NULL; } int atom_type_index_size = 0; int *atom_type_index = get_block_as_int_array(mol, "ATOM_TYPE_INDEX", &atom_type_index_size); if(atom_type_index == NULL) { free(nb_parm_index); free(header); return NULL; } int lj_a_size = 0; float *lj_a = get_block_as_float_array(mol, "LENNARD_JONES_ACOEF", &lj_a_size); if(lj_a == NULL) { free(atom_type_index); free(nb_parm_index); free(header); return NULL; } int lj_b_size = 0; float *lj_b = get_block_as_float_array(mol, "LENNARD_JONES_BCOEF", &lj_b_size); if(lj_b == NULL) { free(lj_a); free(atom_type_index); free(nb_parm_index); free(header); return NULL; } // Extract coordinate arrays float *x, *y, *z; int num_atoms = get_coordinates(mol, &x, &y, &z); int num_atom_types = header[1]; float Evdw = 0.0f; Evdw = calc_vdw_energy( atom_type_index, nb_parm_index, lj_a, lj_b, x, y, z, num_atoms, num_atom_types); free(lj_b); free(lj_a); free(x); free(y); free(z); free(atom_type_index); free(nb_parm_index); free(header); return Py_BuildValue("f", Evdw); }
bool OSystem_PalmBase::pollEvent(Event &event) { ::EventType ev; Boolean handled; UInt32 keyCurrentState; Coord x, y; battery_handler(); timer_handler(); sound_handler(); for(;;) { #if defined(COMPILE_OS5) && defined(PALMOS_ARM) SysEventGet(&ev, evtNoWait); #else EvtGetEvent(&ev, evtNoWait); #endif // check for hardkey repeat for mouse emulation keyCurrentState = KeyCurrentState(); // check_hard_keys(); if (!(keyCurrentState & _keyMouseMask)) { _lastKeyRepeat = 0; } else { if (getMillis() >= (_keyMouseRepeat + _keyMouseDelay)) { _keyMouseRepeat = getMillis(); if (gVars->arrowKeys) { if (keyCurrentState & _keyMouse.bitUp) event.kbd.keycode = 273; else if (keyCurrentState & _keyMouse.bitDown) event.kbd.keycode = 274; else if (keyCurrentState & _keyMouse.bitLeft) event.kbd.keycode = 276; else if (keyCurrentState & _keyMouse.bitRight) event.kbd.keycode = 275; else if (keyCurrentState & _keyMouse.bitButLeft) event.kbd.keycode = chrLineFeed; event.type = EVENT_KEYDOWN; event.kbd.ascii = event.kbd.keycode; event.kbd.flags = 0; } else { Int8 sx = 0; Int8 sy = 0; if (keyCurrentState & _keyMouse.bitUp) sy = -1; else if (keyCurrentState & _keyMouse.bitDown) sy = +1; if (keyCurrentState & _keyMouse.bitLeft) sx = -1; else if (keyCurrentState & _keyMouse.bitRight) sx = +1; if (sx || sy) { simulate_mouse(event, sx, sy, &x, &y); event.type = EVENT_MOUSEMOVE; _lastKey = kKeyMouseMove; } else { x = _mouseCurState.x; y = _mouseCurState.y; if (keyCurrentState & _keyMouse.bitButLeft) { event.type = EVENT_LBUTTONDOWN; _lastKey = kKeyMouseLButton; } else if (_lastKey == kKeyMouseLButton) { event.type = EVENT_LBUTTONUP; _lastKey = kKeyNone; } } event.mouse.x = x; event.mouse.y = y; warpMouse(x, y); // updateCD(); } return true; } } if (ev.eType == keyDownEvent) { switch (ev.data.keyDown.chr) { // ESC key case vchrLaunch: _lastKey = kKeyNone; event.type = EVENT_KEYDOWN; event.kbd.keycode = 27; event.kbd.ascii = 27; event.kbd.flags = 0; return true; // F5 = menu case vchrMenu: _lastKey = kKeyNone; event.type = EVENT_KEYDOWN; event.kbd.keycode = 319; event.kbd.ascii = 319; event.kbd.flags = 0; return true; // if hotsync pressed, etc... case vchrHardCradle: case vchrHardCradle2: case vchrLowBattery: case vchrFind: // case vchrBrightness: // volume control on Zodiac, let other backends disable it case vchrContrast: // do nothing _lastKey = kKeyNone; return true; } } if (check_event(event, &ev)) return true; _lastKey = kKeyNone; // prevent crash when alarm is raised handled = ((ev.eType == keyDownEvent) && (ev.data.keyDown.modifiers & commandKeyMask) && ((ev.data.keyDown.chr == vchrAttnStateChanged) || (ev.data.keyDown.chr == vchrAttnUnsnooze))); // graffiti strokes, auto-off, etc... if (!handled) if (SysHandleEvent(&ev)) continue; switch(ev.eType) { case penMoveEvent: get_coordinates(&ev, x, y); if (y > _screenHeight || y < 0 || x > _screenWidth || x < 0) return false; if (_lastEvent != penMoveEvent && (abs(y - event.mouse.y) <= 2 || abs(x - event.mouse.x) <= 2)) // move only if return false; _lastEvent = penMoveEvent; event.type = EVENT_MOUSEMOVE; event.mouse.x = x; event.mouse.y = y; warpMouse(x, y); return true; case penDownEvent: get_coordinates(&ev, x, y); // indy fight mode if (_useNumPad && !_overlayVisible) { char num = '1'; num += 9 - (3 - (3 * x / _screenWidth )) - (3 * (3 * y / _screenHeight)); event.type = EVENT_KEYDOWN; event.kbd.keycode = num; event.kbd.ascii = num; event.kbd.flags = 0; _lastEvent = keyDownEvent; return true; } _lastEvent = penDownEvent; if (y > _screenHeight || y < 0 || x > _screenWidth || x < 0) return false; event.type = ((gVars->stylusClick || _overlayVisible) ? EVENT_LBUTTONDOWN : EVENT_MOUSEMOVE); event.mouse.x = x; event.mouse.y = y; warpMouse(x, y); return true; case penUpEvent: get_coordinates(&ev, x, y); event.type = ((gVars->stylusClick || _overlayVisible) ? EVENT_LBUTTONUP : EVENT_MOUSEMOVE); if (y > _screenHeight || y < 0 || x > _screenWidth || x < 0) return false; event.mouse.x = x; event.mouse.y = y; warpMouse(x, y); return true; case keyDownEvent: if (ev.data.keyDown.chr == vchrCommand && (ev.data.keyDown.modifiers & commandKeyMask)) { _lastKeyModifier++; _lastKeyModifier %= kModifierCount; if (_lastKeyModifier) draw_osd((kDrawKeyState + _lastKeyModifier - 1), 2, _screenDest.h + 2, true); else draw_osd(kDrawKeyState, 2, _screenDest.h + 2, false); return false; } char mask = 0; UInt16 key = ev.data.keyDown.chr; if (_lastKeyModifier == kModifierNone) { // for keyboard mode if (ev.data.keyDown.modifiers & shiftKeyMask) mask |= KBD_SHIFT; if (ev.data.keyDown.modifiers & controlKeyMask) mask |= KBD_CTRL; if (ev.data.keyDown.modifiers & optionKeyMask) mask |= KBD_ALT; if (ev.data.keyDown.modifiers & commandKeyMask) mask |= KBD_CTRL|KBD_ALT; } else { // for grafiti mode if (_lastKeyModifier == kModifierCommand) mask = KBD_CTRL|KBD_ALT; if (_lastKeyModifier == kModifierAlt) mask = KBD_ALT; if (_lastKeyModifier == kModifierCtrl) mask = KBD_CTRL; } if (_lastKeyModifier) draw_osd(kDrawKeyState, 2, _screenDest.h + 2, false); _lastKeyModifier = kModifierNone; // F1 -> F10 key if (key >= '0' && key <= '9' && mask == (KBD_CTRL|KBD_ALT)) { key = (key == '0') ? 324 : (315 + key - '1'); mask = 0; // exit } else if ((key == 'z' && mask == KBD_CTRL) || (mask == KBD_ALT && key == 'x')) { event.type = EVENT_QUIT; return true; // num pad (indy fight mode) } else if (key == 'n' && mask == (KBD_CTRL|KBD_ALT) && !_overlayVisible) { _useNumPad = !_useNumPad; draw_osd(kDrawFight, _screenDest.w - 34, _screenDest.h + 2, _useNumPad, 1); displayMessageOnOSD(_useNumPad ? "Fight mode on." : "Fight mode off."); return false; } // other keys event.type = EVENT_KEYDOWN; event.kbd.keycode = key; event.kbd.ascii = key; event.kbd.flags = mask; return true; default: return false; }; } }
IMP_FOREACH(Pair pp, local_) { IMP_LOG_VERBOSE("Loading local coordinates for " << m->get_particle_name(pp.second) << std::endl); algebra::Vector3D rf(get_coordinates(fh.get_node(pp.first), ip_factory_)); core::RigidBodyMember(m, pp.second).set_internal_coordinates(rf); }
void cigma::VtkReader:: get_coordinates(const char *loc, double **coordinates, int *nno, int *nsd) { get_coordinates(coordinates, nno, nsd); }
int main(int argc, char **argv) { struct GModule *module; struct { struct Option *text; struct Option *size; struct Option *fgcolor; struct Option *bgcolor; struct Option *line; struct Option *at; struct Option *rotation; struct Option *align; struct Option *linespacing; struct Option *font; struct Option *path; struct Option *charset; struct Option *input; } opt; struct { struct Flag *p; struct Flag *g; struct Flag *b; struct Flag *r; struct Flag *s; } flag; /* options and flags */ char *text; double size; double x, y; int line; double rotation; char align[3]; double linespacing; char bold; /* window info */ struct rectinfo win; /* command file */ FILE *cmd_fp; char buf[512]; int first_text; int linefeed; int set_l; double orig_x, orig_y; double prev_x, prev_y; double set_x, set_y; double east, north; int do_background, fg_color, bg_color; /* initialize the GIS calls */ G_gisinit(argv[0]); module = G_define_module(); G_add_keyword(_("display")); G_add_keyword(_("cartography")); module->description = _("Draws text in the active display frame on the graphics monitor using the current font."); opt.text = G_define_option(); opt.text->key = "text"; opt.text->type = TYPE_STRING; opt.text->required = NO; opt.text->description = _("Text to display"); opt.text->guisection = _("Input"); opt.input = G_define_standard_option(G_OPT_F_INPUT); opt.input->required = NO; opt.input->description = _("Input file"); opt.input->guisection = _("Input"); opt.fgcolor = G_define_option(); opt.fgcolor->key = "color"; opt.fgcolor->type = TYPE_STRING; opt.fgcolor->answer = DEFAULT_COLOR; opt.fgcolor->required = NO; opt.fgcolor->description = _("Text color, either a standard GRASS color or R:G:B triplet"); opt.fgcolor->gisprompt = "old_color,color,color"; opt.fgcolor->guisection = _("Text"); opt.bgcolor = G_define_option(); opt.bgcolor->key = "bgcolor"; opt.bgcolor->type = TYPE_STRING; opt.bgcolor->required = NO; opt.bgcolor->description = _("Text background color, either a standard GRASS color or R:G:B triplet"); opt.bgcolor->gisprompt = "old_color,color,color"; opt.bgcolor->guisection = _("Text"); opt.rotation = G_define_option(); opt.rotation->key = "rotation"; opt.rotation->type = TYPE_DOUBLE; opt.rotation->required = NO; opt.rotation->answer = "0"; opt.rotation->description = _("Rotation angle in degrees (counter-clockwise)"); opt.rotation->guisection = _("Text"); opt.linespacing = G_define_option(); opt.linespacing->key = "linespacing"; opt.linespacing->type = TYPE_DOUBLE; opt.linespacing->required = NO; opt.linespacing->answer = "1.25"; opt.linespacing->description = _("Line spacing"); opt.linespacing->guisection = _("Text"); opt.at = G_define_option(); opt.at->key = "at"; opt.at->key_desc = "x,y"; opt.at->type = TYPE_DOUBLE; opt.at->required = NO; opt.at->description = _("Screen position at which text will begin to be drawn (percentage, [0,0] is lower left)"); opt.at->guisection = _("Position"); opt.line = G_define_option(); opt.line->key = "line"; opt.line->required = NO; opt.line->type = TYPE_INTEGER; opt.line->options = "1-1000"; opt.line->description = _("The screen line number on which text will begin to be drawn"); opt.line->guisection = _("Position"); opt.align = G_define_option(); opt.align->key = "align"; opt.align->type = TYPE_STRING; opt.align->required = NO; opt.align->answer = "ll"; opt.align->options = "ll,lc,lr,cl,cc,cr,ul,uc,ur"; opt.align->description = _("Text alignment"); opt.align->guisection = _("Position"); opt.font = G_define_option(); opt.font->key = "font"; opt.font->type = TYPE_STRING; opt.font->required = NO; opt.font->description = _("Font name"); opt.font->guisection = _("Font settings"); opt.size = G_define_option(); opt.size->key = "size"; opt.size->type = TYPE_DOUBLE; opt.size->required = NO; opt.size->answer = "5"; opt.size->options = "0-100"; opt.size->description = _("Height of letters in percentage of available frame height"); opt.size->guisection = _("Font settings"); opt.path = G_define_standard_option(G_OPT_F_INPUT); opt.path->key = "path"; opt.path->required = NO; opt.path->description = _("Path to font file"); opt.path->gisprompt = "old,font,file"; opt.path->guisection = _("Font settings"); opt.charset = G_define_option(); opt.charset->key = "charset"; opt.charset->type = TYPE_STRING; opt.charset->required = NO; opt.charset->description = _("Text encoding (only applicable to TrueType fonts)"); opt.charset->guisection = _("Font settings"); flag.p = G_define_flag(); flag.p->key = 'p'; flag.p->description = _("Screen position in pixels ([0,0] is top left)"); flag.p->guisection = _("Position"); flag.g = G_define_flag(); flag.g->key = 'g'; flag.g->description = _("Screen position in geographic coordinates"); flag.g->guisection = _("Position"); flag.b = G_define_flag(); flag.b->key = 'b'; flag.b->description = _("Use bold text"); flag.b->guisection = _("Text"); flag.r = G_define_flag(); flag.r->key = 'r'; flag.r->description = _("Use radians instead of degrees for rotation"); flag.r->guisection = _("Text"); flag.s = G_define_flag(); flag.s->key = 's'; flag.s->description = _("Font size is height in pixels"); flag.s->guisection = _("Font settings"); /* check command line */ if (G_parser(argc, argv)) exit(1); /* parse and check options and flags */ if ((opt.line->answer && opt.at->answer) || (flag.p->answer && flag.g->answer)) G_fatal_error(_("Please choose only one placement method")); text = opt.text->answer; line = (opt.line->answer ? atoi(opt.line->answer) : 1); /* calculate rotation angle in radian */ rotation = atof(opt.rotation->answer); if (!flag.r->answer) rotation *= M_PI / 180.0; rotation = fmod(rotation, 2.0 * M_PI); if (rotation < 0.0) rotation += 2.0 * M_PI; strncpy(align, opt.align->answer, 2); linespacing = atof(opt.linespacing->answer); bold = flag.b->answer; D_open_driver(); if (opt.font->answer) D_font(opt.font->answer); else if (opt.path->answer) D_font(opt.path->answer); if (opt.charset->answer) D_encoding(opt.charset->answer); D_setup_unity(0); /* figure out where to put text */ D_get_src(&win.t, &win.b, &win.l, &win.r); if (flag.s->answer) size = atof(opt.size->answer); else #ifdef BACKWARD_COMPATIBILITY size = atof(opt.size->answer) / 100.0 * (win.b - win.t) / linespacing; #else size = atof(opt.size->answer) / 100.0 * (win.b - win.t); #endif fg_color = D_parse_color(opt.fgcolor->answer, TRUE); if (opt.bgcolor->answer) { do_background = 1; bg_color = D_parse_color(opt.bgcolor->answer, TRUE); if (bg_color == 0) /* ie color="none" */ do_background = 0; } else do_background = 0; set_color(opt.fgcolor->answer); orig_x = orig_y = 0; if (opt.at->answer) { if (get_coordinates(&x, &y, &east, &north, win, opt.at->answers, flag.p->answer, flag.g->answer)) G_fatal_error(_("Invalid coordinates")); orig_x = x; orig_y = y; } else { x = win.l + (size * linespacing + 0.5) - size; /* d.text: +5 */ y = win.t + line * (size * linespacing + 0.5); } prev_x = x; prev_y = y; D_text_size(size, size); D_text_rotation(rotation * 180.0 / M_PI); if (text) { double x2, y2; x2 = x; y2 = y; if (text[0]) draw_text(text, &x2, &y2, size, align, rotation, bold, do_background, fg_color, bg_color); /* reset */ D_text_size(5, 5); D_text_rotation(0.0); D_save_command(G_recreate_command()); D_close_driver(); exit(EXIT_SUCCESS); } if (!opt.input->answer || strcmp(opt.input->answer, "-") == 0) cmd_fp = stdin; else { cmd_fp = fopen(opt.input->answer, "r"); if (!cmd_fp) G_fatal_error(_("Unable to open input file <%s>"), opt.input->answer); } if (isatty(fileno(cmd_fp))) fprintf(stderr, _("\nPlease enter text instructions. Enter EOF (ctrl-d) on last line to quit\n")); set_x = set_y = set_l = 0; first_text = 1; linefeed = 1; /* do the plotting */ while (fgets(buf, sizeof(buf), cmd_fp)) { int buf_len; char *buf_ptr, *ptr; buf_len = strlen(buf) - 1; for (; buf[buf_len] == '\r' || buf[buf_len] == '\n'; buf_len--) ; buf[buf_len + 1] = 0; if (buf[0] == '.' && buf[1] != '.') { int i; double d; G_squeeze(buf); /* added 6/91 DBS @ CWU */ for (buf_ptr = buf + 2; *buf_ptr == ' '; buf_ptr++) ; buf_len = strlen(buf_ptr); switch (buf[1] & 0x7f) { case 'F': /* font */ if ((ptr = strchr(buf_ptr, ':'))) *ptr = 0; D_font(buf_ptr); if (ptr) D_encoding(ptr + 1); break; case 'C': /* color */ set_color(buf_ptr); fg_color = D_parse_color(buf_ptr, 1); break; case 'G': /* background color */ bg_color = D_parse_color(buf_ptr, 1); do_background = 1; break; case 'S': /* size */ i = 0; if (strchr("+-", buf_ptr[0])) i = 1; d = atof(buf_ptr); if (buf_ptr[buf_len - 1] != 'p') #ifdef BACKWARD_COMPATIBILITY d *= (win.b - win.t) / 100.0 / linespacing; #else d *= (win.b - win.t) / 100.0; #endif size = d + (i ? size : 0); D_text_size(size, size); break; case 'B': /* bold */ bold = (atoi(buf_ptr) ? 1 : 0); break; case 'A': /* align */ strncpy(align, buf_ptr, 2); break; case 'R': /* rotation */ i = 0; if (strchr("+-", buf_ptr[0])) i = 1; d = atof(buf_ptr); if (buf_ptr[buf_len - 1] != 'r') d *= M_PI / 180.0; d += (i ? rotation : 0.0); rotation = fmod(d, 2.0 * M_PI); if (rotation < 0.0) rotation += 2.0 * M_PI; D_text_rotation(rotation * 180.0 / M_PI); break; case 'I': /* linespacing */ linespacing = atof(buf_ptr); break; case 'X': /* x */ set_l = 0; set_x = 1; i = 0; if (strchr("+-", buf_ptr[0])) i = 1; d = atof(buf_ptr); if (buf_ptr[buf_len - 1] == '%') /* percentage */ d *= (win.r - win.l) / 100.0; else if (buf_ptr[buf_len - 1] != 'p') /* column */ d = (d - 1) * size * linespacing + 0.5; x = prev_x = d + (i ? x : orig_x); break; case 'Y': /* y */ set_l = 0; set_y = 1; i = 0; if (strchr("+-", buf_ptr[0])) i = 1; d = atof(buf_ptr); if (buf_ptr[buf_len - 1] == '%') /* percentage */ d = win.b - d * (win.b - win.t) / 100.0; else if (buf_ptr[buf_len - 1] != 'p') /* row */ d *= size * linespacing + 0.5; y = prev_y = d + (i ? y : orig_y); break; case 'L': /* linefeed */ set_l = 1; linefeed = (atoi(buf_ptr) ? 1 : 0); break; case 'E': i = 0; if (strchr("+-", buf_ptr[0])) i = 1; d = atof(buf_ptr); if (buf_ptr[buf_len - 1] == '%') d *= (win.r - win.l) / 100.0; else if (buf_ptr[buf_len - 1] != 'p') d = D_u_to_d_col(d); x = prev_x = orig_x = d + (i ? orig_x : win.l); break; case 'N': i = 0; if (strchr("+-", buf_ptr[0])) i = 1; d = atof(buf_ptr); if (buf_ptr[buf_len - 1] == '%') d *= (win.b - win.t) / 100.0; else if (buf_ptr[buf_len - 1] != 'p') d = D_u_to_d_row(d); y = prev_y = orig_y = d + (i ? orig_y : win.t); break; } } else { buf_ptr = buf; if (buf[0] == '.' && buf[1] == '.') buf_ptr++; if (!first_text && (linefeed || set_l)) { /* if x is not given, increment x */ if (!set_x) x = prev_x + (size * linespacing + 0.5) * sin(rotation); /* if y is not given, increment y */ if (!set_y) y = prev_y + (size * linespacing + 0.5) * cos(rotation); prev_x = x; prev_y = y; } set_x = set_y = set_l = first_text = 0; draw_text(buf_ptr, &x, &y, size, align, rotation, bold, do_background, fg_color, bg_color); } } if (cmd_fp != stdin) fclose(cmd_fp); /* reset */ D_text_size(5, 5); D_text_rotation(0.0); D_close_driver(); exit(EXIT_SUCCESS); }
IMP_FOREACH(Pair pp, global_) { IMP_LOG_VERBOSE("Loading global coordinates for " << m->get_particle_name(pp.second) << std::endl); algebra::Vector3D rf(get_coordinates(fh.get_node(pp.first), ip_factory_)); core::XYZ(m, pp.second).set_coordinates(rf); }