// 获取DNS服务器的IP地址 int GetDNSAddr(char *Dns1, char *Dns2) { FILE *fp = NULL; char ReadBuf[BUF_LEN] = {0}; int len = 0; char *DNSName = "nameserver "; char *Lastp = NULL; char i = 0; fp = fopen("resolv.conf", "r"); if(fp == NULL) { printf("open resolv.conf error\r\n"); return -1; } while(fgets(ReadBuf, BUF_LEN, fp) != NULL) { len = strlen(ReadBuf); ReadBuf[len -1] = '\0'; if(!strncmp(ReadBuf, DNSName, sizeof(DNSName)))// nameserver一行中,头尾均不能出现空格, 且nameserver必须全为小写 { i++; Lastp = LastPos(" ", ReadBuf);// 定位到了域名服务器地址的前一个空格 if(i == 1) { sprintf(Dns1, "%s", Lastp+1); } else if(i == 2) { sprintf(Dns2, "%s", Lastp+1); } } } if(i == 0)// 配置文件中没有nameserver { printf("No nameserver!\n"); } fclose(fp); }
void GCode::MakeText(string &GcodeTxt, const Settings &settings, ViewProgress * progress) { string GcodeStart = settings.GCode.getStartText(); string GcodeLayer = settings.GCode.getLayerText(); string GcodeEnd = settings.GCode.getEndText(); double lastE = -10; double lastF = 0; // last Feedrate (can be omitted when same) Vector3d pos(0,0,0); Vector3d LastPos(-10,-10,-10); std::stringstream oss; Glib::Date date; date.set_time_current(); Glib::TimeVal time; time.assign_current_time(); GcodeTxt += "; GCode by Repsnapper, "+ date.format_string("%a, %x") + //time.as_iso8601() + "\n"; GcodeTxt += "\n; Startcode\n"+GcodeStart + "; End Startcode\n\n"; layerchanges.clear(); if (progress) progress->restart(_("Collecting GCode"), commands.size()); int progress_steps=(int)(commands.size()/100); if (progress_steps==0) progress_steps=1; for (uint i = 0; i < commands.size(); i++) { char E_letter; if (settings.Slicing.UseTCommand) // use first extruder's code for all extuders E_letter = settings.Extruders[0].GCLetter[0]; else E_letter = settings.Extruders[commands[i].extruder_no].GCLetter[0]; if (progress && i%progress_steps==0 && !progress->update(i)) break; if ( commands[i].Code == LAYERCHANGE ) { layerchanges.push_back(i); if (GcodeLayer.length()>0) GcodeTxt += "\n; Layerchange GCode\n" + GcodeLayer + "; End Layerchange GCode\n\n"; } if ( commands[i].where.z() < 0 ) { cerr << i << " Z < 0 " << commands[i].info() << endl; } else { GcodeTxt += commands[i].GetGCodeText(LastPos, lastE, lastF, settings.Slicing.RelativeEcode, E_letter, settings.Hardware.SpeedAlways) + "\n"; } } GcodeTxt += "\n; End GCode\n" + GcodeEnd + "\n"; buffer->set_text (GcodeTxt); // save zpos line numbers for faster finding buffer_zpos_lines.clear(); uint blines = buffer->get_line_count(); for (uint i = 0; i < blines; i++) { const string line = getLineAt(buffer, i); if (line.find("Z") != string::npos || line.find("z") != string::npos) buffer_zpos_lines.push_back(i); } if (progress) progress->stop(); }
void GCode::MakeText(string &GcodeTxt, const string &GcodeStart, const string &GcodeLayer, const string &GcodeEnd, bool RelativeEcode, ViewProgress * progress) { double lastE = -10; double lastF = 0; // last Feedrate (can be omitted when same) Vector3d pos(0,0,0); Vector3d LastPos(-10,-10,-10); std::stringstream oss; Glib::Date date; date.set_time_current(); Glib::TimeVal time; time.assign_current_time(); GcodeTxt += "; GCode by Repsnapper, "+ date.format_string("%a, %x") + //time.as_iso8601() + "\n"; GcodeTxt += "\n; Startcode\n"+GcodeStart + "; End Startcode\n\n"; layerchanges.clear(); progress->restart(_("Collecting GCode"),commands.size()); int progress_steps=(int)(commands.size()/100); if (progress_steps==0) progress_steps=1; for (uint i = 0; i < commands.size(); i++) { if (i%progress_steps==0) if (!progress->update(i)) break; if ( commands[i].Code == LAYERCHANGE ) { layerchanges.push_back(i); if (GcodeLayer.length()>0) GcodeTxt += "\n; Layerchange GCode\n" + GcodeLayer + "; End Layerchange GCode\n\n"; } if ( commands[i].where.z() < 0 ) { cerr << i << " Z < 0 " << commands[i].info() << endl; } else { GcodeTxt += commands[i].GetGCodeText(LastPos, lastE, lastF, RelativeEcode) + "\n"; } } GcodeTxt += "\n; End GCode\n" + GcodeEnd + "\n"; buffer->set_text (GcodeTxt); // save zpos line numbers for faster finding buffer_zpos_lines.clear(); uint blines = buffer->get_line_count(); for (uint i = 0; i < blines; i++) { const string line = getLineAt(buffer, i); if (line.find("Z") != string::npos || line.find("z") != string::npos) buffer_zpos_lines.push_back(i); } // oss.str( "" ); // switch(commands[i].Code) // { // case SELECTEXTRUDER: // oss << "T0\n"; // add_text_filter_nan(oss.str(), GcodeTxt); // //GcodeTxt += oss.str(); // break; // case SETSPEED: // commands[i].where.z() = LastPos.z(); // commands[i].e = lastE; // case ZMOVE: // commands[i].where.x() = LastPos.x(); // commands[i].where.y() = LastPos.y(); // case COORDINATEDMOTION: // if ((commands[i].where.x() != LastPos.x()) + // (commands[i].where.y() != LastPos.y()) + // (commands[i].where.z() != LastPos.z()) != 0 && // AntioozeDistance != 0 && commands[i].e == lastE && // !Use3DGcode && AntioozeDistance != 0) // { // if (UseIncrementalEcode) // { // oss << "G1 E" << (lastE - AntioozeDistance) << " F" << AntioozeSpeed << " ;antiooze retract\n"; // } // else // { // oss << "G1 E" << -(AntioozeDistance) << " F" << AntioozeSpeed << " ;antiooze retract\n"; // } // } // oss << "G1 "; // if(commands[i].where.x() != LastPos.x()) // oss << "X" << commands[i].where.x() << " "; // if(commands[i].where.y() != LastPos.y()) // oss << "Y" << commands[i].where.y() << " "; // if(commands[i].where.z() != LastPos.z()) // oss << "Z" << commands[i].where.z() << " "; // if(commands[i].e != lastE) // { // if(UseIncrementalEcode) // in incremental mode, the same is nothing // { // if(commands[i].e != lastE) // oss << "E" << commands[i].e << " "; // } // else // { // if(commands[i].e >= 0.0) // oss << "E" << commands[i].e << " "; // } // } // oss << "F" << commands[i].f; // if(commands[i].comment.length() != 0) // oss << " ;" << commands[i].comment << "\n"; // else // oss << "\n"; // if ((commands[i].where.x() != LastPos.x()) + // (commands[i].where.y() != LastPos.y()) + // (commands[i].where.z() != LastPos.z()) != 0 && // AntioozeDistance != 0 && // commands[i].e == lastE && // !Use3DGcode && AntioozeDistance != 0) // { // if (UseIncrementalEcode) // { // oss << "G1 E" << lastE << " F" << AntioozeSpeed << " ;antiooze return\n"; // } // else // { // oss << "G1 E" << AntioozeDistance << " F" << AntioozeSpeed << " ;antiooze return\n"; // } // } // add_text_filter_nan(oss.str(), GcodeTxt); // //GcodeTxt += oss.str(); // if(commands[i].Code == ZMOVE && commands[i].where.z() != LastPos.z()) // add_text_filter_nan(GcodeLayer + "\n", GcodeTxt); // //GcodeTxt += GcodeLayer + "\n"; // LastPos = commands[i].where; // if( commands[i].e >= 0.0) // lastE = commands[i].e; // break; // case EXTRUDERON: // // Dont switch extruder on/off right after eachother // if(i != 0 && commands[i-1].Code == EXTRUDEROFF) continue; // oss << "M101\n"; // add_text_filter_nan(oss.str(), GcodeTxt); // //GcodeTxt += oss.str(); // break; // case EXTRUDEROFF: // // Dont switch extruder on/off right after eachother // if(i != 0 && (i+1) < commands.size() && // commands[i+1].Code == EXTRUDERON) continue; // // don't switch extruder off twize // if(i != 0 && (i+1) < commands.size() && // commands[i+1].Code == EXTRUDEROFF) continue; // oss << "M103\n"; // add_text_filter_nan(oss.str(), GcodeTxt); // //GcodeTxt += oss.str(); // break; // case COORDINATEDMOTION3D: // oss << "G1 X" << commands[i].where.x() << " Y" << commands[i].where.y() << " Z" << commands[i].where.z(); // oss << " F" << commands[i].f; // if(commands[i].comment.length() != 0) // oss << " ;" << commands[i].comment << "\n"; // else // oss << "\n"; // add_text_filter_nan(oss.str(), GcodeTxt); // //GcodeTxt += oss.str(); // LastPos = commands[i].where; // break; // case RAPIDMOTION: // oss << "G0 X" << commands[i].where.x() << " Y" << commands[i].where.y() << " Z" << commands[i].where.z() << "\n"; // add_text_filter_nan(oss.str(), GcodeTxt); // //GcodeTxt += oss.str(); // LastPos = commands[i].where; // break; // case GOTO: // oss << "G92"; // if(commands[i].where.x() != LastPos.x() && commands[i].where.x() >= 0) // { // LastPos.x() = commands[i].where.x(); // oss << " X" << commands[i].where.x(); // } // if(commands[i].where.y() != LastPos.y() && commands[i].where.y() >= 0) // { // LastPos.y() = commands[i].where.y(); // oss << " Y" << commands[i].where.y(); // } // if(commands[i].where.z() != LastPos.z() && commands[i].where.z() >= 0) // { // LastPos.z() = commands[i].where.z(); // oss << " Z" << commands[i].where.z(); // } // if(commands[i].e != lastE && commands[i].e >= 0.0) // { // lastE = commands[i].e; // oss << " E" << commands[i].e; // } // oss << "\n"; // add_text_filter_nan(oss.str(), GcodeTxt); // //GcodeTxt += oss.str(); // break; // default: // break; // ignored CGCode // } // pos = commands[i].where; // cerr<< oss.str()<< endl; //} }
void FEdModeGeometry::RenderPoly( const FSceneView* View, FViewport* Viewport, FPrimitiveDrawInterface* PDI ) { for( int32 ObjectIdx = 0 ; ObjectIdx < GeomObjects.Num() ; ++ObjectIdx ) { const FGeomObject* GeomObject = GeomObjects[ObjectIdx]; FLinearColor UnselectedColor = GeomObject->GetActualBrush()->GetWireColor(); UnselectedColor.A = .1f; FLinearColor SelectedColor = GetDefault<UEditorStyleSettings>()->SelectionColor; SelectedColor.A = .5f; // Allocate the material proxy and register it so it can be deleted properly once the rendering is done with it. FDynamicColoredMaterialRenderProxy* SelectedColorInstance = new FDynamicColoredMaterialRenderProxy(GEngine->GeomMaterial->GetRenderProxy(false),SelectedColor ); PDI->RegisterDynamicResource( SelectedColorInstance ); FDynamicColoredMaterialRenderProxy* UnselectedColorInstance = new FDynamicColoredMaterialRenderProxy(GEngine->GeomMaterial->GetRenderProxy(false),UnselectedColor); PDI->RegisterDynamicResource( UnselectedColorInstance ); // Render selected filled polygons. for( int32 PolyIdx = 0 ; PolyIdx < GeomObject->PolyPool.Num() ; ++PolyIdx ) { const FGeomPoly* GeomPoly = &GeomObject->PolyPool[PolyIdx]; PDI->SetHitProxy( new HGeomPolyProxy(const_cast<FGeomObject*>(GeomPoly->GetParentObject()),PolyIdx) ); { FDynamicMeshBuilder MeshBuilder; TArray<FVector> Verts; // Look at the edge list and create a list of vertices to render from. FVector LastPos(0); for( int32 EdgeIdx = 0 ; EdgeIdx < GeomPoly->EdgeIndices.Num() ; ++EdgeIdx ) { const FGeomEdge* GeomEdge = &GeomPoly->GetParentObject()->EdgePool[ GeomPoly->EdgeIndices[EdgeIdx] ]; if( EdgeIdx == 0 ) { Verts.Add( GeomPoly->GetParentObject()->VertexPool[ GeomEdge->VertexIndices[0] ] ); LastPos = GeomPoly->GetParentObject()->VertexPool[ GeomEdge->VertexIndices[0] ]; } else if( GeomPoly->GetParentObject()->VertexPool[ GeomEdge->VertexIndices[0] ].Equals( LastPos ) ) { Verts.Add( GeomPoly->GetParentObject()->VertexPool[ GeomEdge->VertexIndices[1] ] ); LastPos = GeomPoly->GetParentObject()->VertexPool[ GeomEdge->VertexIndices[1] ]; } else { Verts.Add( GeomPoly->GetParentObject()->VertexPool[ GeomEdge->VertexIndices[0] ] ); LastPos = GeomPoly->GetParentObject()->VertexPool[ GeomEdge->VertexIndices[0] ]; } } // Draw Polygon Triangles const int32 VertexOffset = MeshBuilder.AddVertex(Verts[0], FVector2D::ZeroVector, FVector(1,0,0), FVector(0,1,0), FVector(0,0,1), FColor(255,255,255)); MeshBuilder.AddVertex(Verts[1], FVector2D::ZeroVector, FVector(1,0,0), FVector(0,1,0), FVector(0,0,1), FColor(255,255,255)); for( int32 VertIdx = 2 ; VertIdx < Verts.Num() ; ++VertIdx ) { MeshBuilder.AddVertex(Verts[VertIdx], FVector2D::ZeroVector, FVector(1,0,0), FVector(0,1,0), FVector(0,0,1), FColor(255,255,255)); MeshBuilder.AddTriangle( VertexOffset + VertIdx - 1, VertexOffset, VertexOffset + VertIdx); } if( GeomPoly->IsSelected() ) { MeshBuilder.Draw(PDI, GeomObject->GetActualBrush()->ActorToWorld().ToMatrixWithScale(), SelectedColorInstance, SDPG_World, false ); } else { // We only draw unselected polygons in the perspective viewport if( !Viewport->GetClient()->IsOrtho() ) { // Unselected polygons are drawn at the world level but are bumped slightly forward to avoid z-fighting MeshBuilder.Draw(PDI, GeomObject->GetActualBrush()->ActorToWorld().ToMatrixWithScale(), UnselectedColorInstance, SDPG_World, false ); } } } PDI->SetHitProxy( NULL ); } } }