bool GERBER_DRAW_ITEM::GetTextD_CodePrms( double& aSize, VECTOR2D& aPos, double& aOrientation ) { // aOrientation is returned in radians int size; wxPoint pos; if( ! GetTextD_CodePrms( size, pos, aOrientation ) ) return false; aPos = pos; aSize = (double) size; aOrientation = DECIDEG2RAD( aOrientation ); return true; }
void RotatePoint( double* pX, double* pY, double angle ) { double tmp; NORMALIZE_ANGLE_POS( angle ); // Cheap and dirty optimizations for 0, 90, 180, and 270 degrees. if( angle == 0 ) return; if( angle == 900 ) /* sin = 1, cos = 0 */ { tmp = *pX; *pX = *pY; *pY = -tmp; } else if( angle == 1800 ) /* sin = 0, cos = -1 */ { *pX = -*pX; *pY = -*pY; } else if( angle == 2700 ) /* sin = -1, cos = 0 */ { tmp = *pX; *pX = -*pY; *pY = tmp; } else { double fangle = DECIDEG2RAD( angle ); double sinus = sin( fangle ); double cosinus = cos( fangle ); double fpx = (*pY * sinus ) + (*pX * cosinus ); double fpy = (*pY * cosinus ) - (*pX * sinus ); *pX = fpx; *pY = fpy; } }
static void export_vrml_module( MODEL_VRML& aModel, BOARD* aPcb, MODULE* aModule, std::ofstream& aOutputFile, double aVRMLModelsToBiu, bool aExport3DFiles, const wxString& a3D_Subdir ) { // Reference and value if( aModule->Reference().IsVisible() ) export_vrml_text_module( &aModule->Reference() ); if( aModule->Value().IsVisible() ) export_vrml_text_module( &aModule->Value() ); // Export module edges for( EDA_ITEM* item = aModule->GraphicalItems(); item; item = item->Next() ) { switch( item->Type() ) { case PCB_MODULE_TEXT_T: export_vrml_text_module( static_cast<TEXTE_MODULE*>( item ) ); break; case PCB_MODULE_EDGE_T: export_vrml_edge_module( aModel, static_cast<EDGE_MODULE*>( item ), aModule->GetOrientation() ); break; default: break; } } // Export pads for( D_PAD* pad = aModule->Pads(); pad; pad = pad->Next() ) export_vrml_pad( aModel, aPcb, pad ); bool isFlipped = aModule->GetLayer() == B_Cu; // Export the object VRML model(s) for( S3D_MASTER* vrmlm = aModule->Models(); vrmlm; vrmlm = vrmlm->Next() ) { if( !vrmlm->Is3DType( S3D_MASTER::FILE3D_VRML ) ) continue; wxString fname = vrmlm->GetShape3DFullFilename(); fname.Replace( wxT( "\\" ), wxT( "/" ) ); wxString source_fname = fname; if( aExport3DFiles ) { // Change illegal characters in filenames ChangeIllegalCharacters( fname, true ); fname = a3D_Subdir + wxT( "/" ) + fname; if( !wxFileExists( fname ) ) wxCopyFile( source_fname, fname ); } /* Calculate 3D shape rotation: * this is the rotation parameters, with an additional 180 deg rotation * for footprints that are flipped * When flipped, axis rotation is the horizontal axis (X axis) */ double rotx = -vrmlm->m_MatRotation.x; double roty = -vrmlm->m_MatRotation.y; double rotz = -vrmlm->m_MatRotation.z; if( isFlipped ) { rotx += 180.0; NEGATE( roty ); NEGATE( rotz ); } // Do some quaternion munching double q1[4], q2[4], rot[4]; build_quat( 1, 0, 0, DEG2RAD( rotx ), q1 ); build_quat( 0, 1, 0, DEG2RAD( roty ), q2 ); compose_quat( q1, q2, q1 ); build_quat( 0, 0, 1, DEG2RAD( rotz ), q2 ); compose_quat( q1, q2, q1 ); // Note here aModule->GetOrientation() is in 0.1 degrees, // so module rotation has to be converted to radians build_quat( 0, 0, 1, DECIDEG2RAD( aModule->GetOrientation() ), q2 ); compose_quat( q1, q2, q1 ); from_quat( q1, rot ); aOutputFile << "Transform {\n"; // A null rotation would fail the acos! if( rot[3] != 0.0 ) { aOutputFile << " rotation " << std::setprecision( 3 ); aOutputFile << rot[0] << " " << rot[1] << " " << rot[2] << " " << rot[3] << "\n"; } // adjust 3D shape local offset position // they are given in inch, so they are converted in board IU. double offsetx = vrmlm->m_MatPosition.x * IU_PER_MILS * 1000.0; double offsety = vrmlm->m_MatPosition.y * IU_PER_MILS * 1000.0; double offsetz = vrmlm->m_MatPosition.z * IU_PER_MILS * 1000.0; if( isFlipped ) NEGATE( offsetz ); else // In normal mode, Y axis is reversed in Pcbnew. NEGATE( offsety ); RotatePoint( &offsetx, &offsety, aModule->GetOrientation() ); aOutputFile << " translation " << std::setprecision( aModel.precision ); aOutputFile << (( offsetx + aModule->GetPosition().x) * aModel.scale + aModel.tx ) << " "; aOutputFile << ( -(offsety + aModule->GetPosition().y) * aModel.scale - aModel.ty ) << " "; aOutputFile << ( (offsetz * aModel.scale ) + aModel.GetLayerZ( aModule->GetLayer() ) ) << "\n"; aOutputFile << " scale "; aOutputFile << ( vrmlm->m_MatScale.x * aVRMLModelsToBiu ) << " "; aOutputFile << ( vrmlm->m_MatScale.y * aVRMLModelsToBiu ) << " "; aOutputFile << ( vrmlm->m_MatScale.z * aVRMLModelsToBiu ) << "\n"; if( fname.EndsWith( wxT( "x3d" ) ) ) { X3D_MODEL_PARSER* parser = new X3D_MODEL_PARSER( vrmlm ); if( parser ) { // embed x3d model in vrml format double vrml_to_x3d = aVRMLModelsToBiu; parser->Load( fname, vrml_to_x3d ); try { aOutputFile << " children [\n "; aOutputFile << TO_UTF8( parser->VRML2_representation() ) << " ]\n"; aOutputFile << " }\n"; } catch( const std::exception& e ) { delete parser; throw; } } } else { aOutputFile << " children [\n Inline {\n url \""; aOutputFile << TO_UTF8( fname ) << "\"\n } ]\n"; aOutputFile << " }\n"; } } }
static void export_vrml_module( MODEL_VRML& aModel, BOARD* aPcb, MODULE* aModule, std::ofstream& aOutputFile, double aVRMLModelsToBiu, bool aExport3DFiles, bool aUseRelativePaths, const wxString& a3D_Subdir ) { // Reference and value if( aModule->Reference().IsVisible() ) export_vrml_text_module( &aModule->Reference() ); if( aModule->Value().IsVisible() ) export_vrml_text_module( &aModule->Value() ); // Export module edges for( EDA_ITEM* item = aModule->GraphicalItems(); item; item = item->Next() ) { switch( item->Type() ) { case PCB_MODULE_TEXT_T: export_vrml_text_module( static_cast<TEXTE_MODULE*>( item ) ); break; case PCB_MODULE_EDGE_T: export_vrml_edge_module( aModel, static_cast<EDGE_MODULE*>( item ), aModule->GetOrientation() ); break; default: break; } } // Export pads for( D_PAD* pad = aModule->Pads(); pad; pad = pad->Next() ) export_vrml_pad( aModel, aPcb, pad ); bool isFlipped = aModule->GetLayer() == B_Cu; // Export the object VRML model(s) for( S3D_MASTER* vrmlm = aModule->Models(); vrmlm; vrmlm = vrmlm->Next() ) { if( !vrmlm->Is3DType( S3D_MASTER::FILE3D_VRML ) ) continue; wxFileName modelFileName = vrmlm->GetShape3DFullFilename(); wxFileName destFileName( a3D_Subdir, modelFileName.GetName(), modelFileName.GetExt() ); // Only copy VRML files. if( modelFileName.FileExists() && modelFileName.GetExt() == wxT( "wrl" ) ) { if( aExport3DFiles ) { wxDateTime srcModTime = modelFileName.GetModificationTime(); wxDateTime destModTime = srcModTime; destModTime.SetToCurrent(); if( destFileName.FileExists() ) destModTime = destFileName.GetModificationTime(); // Only copy the file if it doesn't exist or has been modified. This eliminates // the redundant file copies. if( srcModTime != destModTime ) { wxLogDebug( wxT( "Copying 3D model %s to %s." ), GetChars( modelFileName.GetFullPath() ), GetChars( destFileName.GetFullPath() ) ); if( !wxCopyFile( modelFileName.GetFullPath(), destFileName.GetFullPath() ) ) continue; } } /* Calculate 3D shape rotation: * this is the rotation parameters, with an additional 180 deg rotation * for footprints that are flipped * When flipped, axis rotation is the horizontal axis (X axis) */ double rotx = -vrmlm->m_MatRotation.x; double roty = -vrmlm->m_MatRotation.y; double rotz = -vrmlm->m_MatRotation.z; if( isFlipped ) { rotx += 180.0; NEGATE( roty ); NEGATE( rotz ); } // Do some quaternion munching double q1[4], q2[4], rot[4]; build_quat( 1, 0, 0, DEG2RAD( rotx ), q1 ); build_quat( 0, 1, 0, DEG2RAD( roty ), q2 ); compose_quat( q1, q2, q1 ); build_quat( 0, 0, 1, DEG2RAD( rotz ), q2 ); compose_quat( q1, q2, q1 ); // Note here aModule->GetOrientation() is in 0.1 degrees, // so module rotation has to be converted to radians build_quat( 0, 0, 1, DECIDEG2RAD( aModule->GetOrientation() ), q2 ); compose_quat( q1, q2, q1 ); from_quat( q1, rot ); aOutputFile << "Transform {\n"; // A null rotation would fail the acos! if( rot[3] != 0.0 ) { aOutputFile << " rotation " << std::setprecision( 3 ); aOutputFile << rot[0] << " " << rot[1] << " " << rot[2] << " " << rot[3] << "\n"; } // adjust 3D shape local offset position // they are given in inch, so they are converted in board IU. double offsetx = vrmlm->m_MatPosition.x * IU_PER_MILS * 1000.0; double offsety = vrmlm->m_MatPosition.y * IU_PER_MILS * 1000.0; double offsetz = vrmlm->m_MatPosition.z * IU_PER_MILS * 1000.0; if( isFlipped ) NEGATE( offsetz ); else // In normal mode, Y axis is reversed in Pcbnew. NEGATE( offsety ); RotatePoint( &offsetx, &offsety, aModule->GetOrientation() ); aOutputFile << " translation " << std::setprecision( aModel.precision ); aOutputFile << ( ( offsetx + aModule->GetPosition().x ) * aModel.scale + aModel.tx ) << " "; aOutputFile << ( -(offsety + aModule->GetPosition().y) * aModel.scale - aModel.ty ) << " "; aOutputFile << ( (offsetz * aModel.scale ) + aModel.GetLayerZ( aModule->GetLayer() ) ) << "\n"; aOutputFile << " scale "; aOutputFile << ( vrmlm->m_MatScale.x * aVRMLModelsToBiu ) << " "; aOutputFile << ( vrmlm->m_MatScale.y * aVRMLModelsToBiu ) << " "; aOutputFile << ( vrmlm->m_MatScale.z * aVRMLModelsToBiu ) << "\n"; aOutputFile << " children [\n Inline {\n url \""; if( aUseRelativePaths ) { wxFileName tmp = destFileName; tmp.SetExt( wxT( "" ) ); tmp.SetName( wxT( "" ) ); tmp.RemoveLastDir(); destFileName.MakeRelativeTo( tmp.GetPath() ); } wxString fn = destFileName.GetFullPath(); fn.Replace( wxT( "\\" ), wxT( "/" ) ); aOutputFile << TO_UTF8( fn ) << "\"\n } ]\n"; aOutputFile << " }\n"; } } }
void SVG_PLOTTER::Arc( const wxPoint& centre, double StAngle, double EndAngle, int radius, FILL_T fill, int width ) { /* Draws an arc of a circle, centred on (xc,yc), with starting point * (x1, y1) and ending at (x2, y2). The current pen is used for the outline * and the current brush for filling the shape. * * The arc is drawn in an anticlockwise direction from the start point to * the end point */ if( radius <= 0 ) return; if( StAngle > EndAngle ) EXCHG( StAngle, EndAngle ); setFillMode( fill ); SetCurrentLineWidth( width ); // Calculate start point. DPOINT centre_dev = userToDeviceCoordinates( centre ); double radius_dev = userToDeviceSize( radius ); if( !m_yaxisReversed ) // Should be never the case { double tmp = StAngle; StAngle = -EndAngle; EndAngle = -tmp; } if( m_plotMirror ) { if( m_mirrorIsHorizontal ) { StAngle = 1800.0 -StAngle; EndAngle = 1800.0 -EndAngle; EXCHG( StAngle, EndAngle ); } else { StAngle = -StAngle; EndAngle = -EndAngle; } } DPOINT start; start.x = radius_dev; RotatePoint( &start.x, &start.y, StAngle ); DPOINT end; end.x = radius_dev; RotatePoint( &end.x, &end.y, EndAngle ); start += centre_dev; end += centre_dev; double theta1 = DECIDEG2RAD( StAngle ); if( theta1 < 0 ) theta1 = theta1 + M_PI * 2; double theta2 = DECIDEG2RAD( EndAngle ); if( theta2 < 0 ) theta2 = theta2 + M_PI * 2; if( theta2 < theta1 ) theta2 = theta2 + M_PI * 2; int flg_arc = 0; // flag for large or small arc. 0 means less than 180 degrees if( fabs( theta2 - theta1 ) > M_PI ) flg_arc = 1; int flg_sweep = 0; // flag for sweep always 0 // Draw a single arc: an arc is one of 3 curve commands (2 other are 2 bezier curves) // params are start point, radius1, radius2, X axe rotation, // flag arc size (0 = small arc > 180 deg, 1 = large arc > 180 deg), // sweep arc ( 0 = CCW, 1 = CW), // end point fprintf( outputFile, "<path d=\"M%g %g A%g %g 0.0 %d %d %g %g \" />\n", start.x, start.y, radius_dev, radius_dev, flg_arc, flg_sweep, end.x, end.y ); }
/** This is the core for postscript/PDF text alignment * It computes the transformation matrix to generate a user space * system aligned with the text. Even the PS uses the concat * operator to simplify PDF generation (concat is everything PDF * has to modify the CTM. Lots of parameters, both in and out. */ void PSLIKE_PLOTTER::computeTextParameters( const wxPoint& aPos, const wxString& aText, int aOrient, const wxSize& aSize, enum EDA_TEXT_HJUSTIFY_T aH_justify, enum EDA_TEXT_VJUSTIFY_T aV_justify, int aWidth, bool aItalic, bool aBold, double *wideningFactor, double *ctm_a, double *ctm_b, double *ctm_c, double *ctm_d, double *ctm_e, double *ctm_f, double *heightFactor ) { // Compute the starting position (compensated for alignment) wxPoint start_pos = aPos; // This is an approximation of the text bounds (in IUs) int tw = returnPostscriptTextWidth( aText, aSize.x, aItalic, aWidth ); int th = aSize.y; int dx, dy; switch( aH_justify ) { case GR_TEXT_HJUSTIFY_CENTER: dx = -tw / 2; break; case GR_TEXT_HJUSTIFY_RIGHT: dx = -tw; break; case GR_TEXT_HJUSTIFY_LEFT: dx = 0; break; } switch( aV_justify ) { case GR_TEXT_VJUSTIFY_CENTER: dy = th / 2; break; case GR_TEXT_VJUSTIFY_TOP: dy = th; break; case GR_TEXT_VJUSTIFY_BOTTOM: dy = 0; break; } RotatePoint( &dx, &dy, aOrient ); RotatePoint( &tw, &th, aOrient ); start_pos.x += dx; start_pos.y += dy; DPOINT pos_dev = userToDeviceCoordinates( start_pos ); DPOINT sz_dev = userToDeviceSize( aSize ); // Now returns the final values... the widening factor *wideningFactor = sz_dev.y / sz_dev.x; // The CTM transformation matrix double alpha = DECIDEG2RAD( aOrient ); double sinalpha = sin( alpha ); double cosalpha = cos( alpha ); *ctm_a = cosalpha; *ctm_b = sinalpha; *ctm_c = -sinalpha; *ctm_d = cosalpha; *ctm_e = pos_dev.x; *ctm_f = pos_dev.y; // This is because the letters are less than 1 unit high *heightFactor = sz_dev.y / postscriptTextAscent; }
void TransformRoundChamferedRectToPolygon( SHAPE_POLY_SET& aCornerBuffer, const wxPoint& aPosition, const wxSize& aSize, double aRotation, int aCornerRadius, double aChamferRatio, int aChamferCorners, int aCircleToSegmentsCount ) { // Build the basic shape in orientation 0.0, position 0,0 for chamfered corners // or in actual position/orientation for round rect only wxPoint corners[4]; GetRoundRectCornerCenters( corners, aCornerRadius, aChamferCorners ? wxPoint( 0, 0 ) : aPosition, aSize, aChamferCorners ? 0.0 : aRotation ); SHAPE_POLY_SET outline; outline.NewOutline(); for( int ii = 0; ii < 4; ++ii ) outline.Append( corners[ii].x, corners[ii].y ); outline.Inflate( aCornerRadius, aCircleToSegmentsCount ); if( aChamferCorners == RECT_NO_CHAMFER ) // no chamfer { // Add the outline: aCornerBuffer.Append( outline ); return; } // Now we have the round rect outline, in position 0,0 orientation 0.0. // Chamfer the corner(s). int chamfer_value = aChamferRatio * std::min( aSize.x, aSize.y ); SHAPE_POLY_SET chamfered_corner; // corner shape for the current corner to chamfer int corner_id[4] = { RECT_CHAMFER_TOP_LEFT, RECT_CHAMFER_TOP_RIGHT, RECT_CHAMFER_BOTTOM_LEFT, RECT_CHAMFER_BOTTOM_RIGHT }; // Depending on the corner position, signX[] and signY[] give the sign of chamfer // coordinates relative to the corner position // The first corner is the top left corner, then top right, bottom left and bottom right int signX[4] = {1, -1, 1,-1 }; int signY[4] = {1, 1, -1,-1 }; for( int ii = 0; ii < 4; ii++ ) { if( (corner_id[ii] & aChamferCorners) == 0 ) continue; VECTOR2I corner_pos( -signX[ii]*aSize.x/2, -signY[ii]*aSize.y/2 ); if( aCornerRadius ) { // We recreate a rectangular area covering the full rounded corner (max size = aSize/2) // to rebuild the corner before chamfering, to be sure the rounded corner shape does not // overlap the chamfered corner shape: chamfered_corner.RemoveAllContours(); chamfered_corner.NewOutline(); chamfered_corner.Append( 0, 0 ); chamfered_corner.Append( 0, signY[ii]*aSize.y/2 ); chamfered_corner.Append( signX[ii]*aSize.x/2, signY[ii]*aSize.y/2 ); chamfered_corner.Append( signX[ii]*aSize.x/2, 0 ); chamfered_corner.Move( corner_pos ); outline.BooleanAdd( chamfered_corner, SHAPE_POLY_SET::PM_STRICTLY_SIMPLE ); } // Now chamfer this corner chamfered_corner.RemoveAllContours(); chamfered_corner.NewOutline(); chamfered_corner.Append( 0, 0 ); chamfered_corner.Append( 0, signY[ii]*chamfer_value ); chamfered_corner.Append( signX[ii]*chamfer_value, 0 ); chamfered_corner.Move( corner_pos ); outline.BooleanSubtract( chamfered_corner, SHAPE_POLY_SET::PM_STRICTLY_SIMPLE ); } // Rotate and move the outline: if( aRotation != 0.0 ) outline.Rotate( DECIDEG2RAD( -aRotation ), VECTOR2I( 0, 0 ) ); outline.Move( VECTOR2I( aPosition ) ); // Add the outline: aCornerBuffer.Append( outline ); }