Ejemplo n.º 1
0
// add a component at the given position and orientation
bool PCBMODEL::AddComponent( const std::string& aFileName, const std::string aRefDes,
    bool aBottom, DOUBLET aPosition, double aRotation,
    TRIPLET aOffset, TRIPLET aOrientation )
{
    // first retrieve a label
    TDF_Label lmodel;

    if( !getModelLabel( aFileName, lmodel ) )
    {
        std::ostringstream ostr;
        ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
        ostr << "  * no model for filename '" << aFileName << "'\n";
        wxLogMessage( "%s\n", ostr.str().c_str() );
        return false;
    }

    // calculate the Location transform
    TopLoc_Location toploc;

    if( !getModelLocation( aBottom, aPosition, aRotation, aOffset, aOrientation, toploc ) )
    {
        std::ostringstream ostr;
        ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
        ostr << "  * no location data for filename '" << aFileName << "'\n";
        wxLogMessage( "%s\n", ostr.str().c_str() );
        return false;
    }

    // add the located sub-assembly
    TDF_Label llabel = m_assy->AddComponent( m_assy_label, lmodel, toploc );

    if( llabel.IsNull() )
    {
        std::ostringstream ostr;
        ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
        ostr << "  * could not add component with filename '" << aFileName << "'\n";
        wxLogMessage( "%s\n", ostr.str().c_str() );
        return false;
    }

    // attach the RefDes name
    TCollection_ExtendedString refdes( aRefDes.c_str() );
    TDataStd_Name::Set( llabel, refdes );

    return true;
}
Ejemplo n.º 2
0
bool PCBMODEL::getModelLabel( const std::string aFileName, TDF_Label& aLabel )
{
    MODEL_MAP::const_iterator mm = m_models.find( aFileName );

    if( mm != m_models.end() )
    {
        aLabel = mm->second;
        return true;
    }

    aLabel.Nullify();

    Handle( TDocStd_Document )  doc;
    m_app->NewDocument( "MDTV-XCAF", doc );

    FormatType modelFmt = fileType( aFileName.c_str() );

    switch( modelFmt )
    {
        case FMT_IGES:
            if( !readIGES( doc, aFileName.c_str() ) )
            {
                std::ostringstream ostr;
#ifdef __WXDEBUG__
                ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
#endif /* __WXDEBUG */
                ostr << "  * readIGES() failed on filename '" << aFileName << "'\n";
                wxLogMessage( "%s", ostr.str().c_str() );
                return false;
            }
            break;

        case FMT_STEP:
            if( !readSTEP( doc, aFileName.c_str() ) )
            {
                std::ostringstream ostr;
#ifdef __WXDEBUG__
                ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
#endif /* __WXDEBUG */
                ostr << "  * readSTEP() failed on filename '" << aFileName << "'\n";
                wxLogMessage( "%s", ostr.str().c_str() );
                return false;
            }
            break;

        case FMT_WRL:
            /* WRL files are preferred for internal rendering,
             * due to superior material properties, etc.
             * However they are not suitable for MCAD export.
             *
             * If a .wrl file is specified, attempt to locate
             * a replacement file for it.
             *
             * If a valid replacement file is found, the label
             * for THAT file will be associated with the .wrl file
             *
             */
            {
                wxFileName wrlName( aFileName );

                wxString basePath = wrlName.GetPath();
                wxString baseName = wrlName.GetName();

                // List of alternate files to look for
                // Given in order of preference
                // (Break if match is found)
                wxArrayString alts;

                // Step files
                alts.Add( "stp" );
                alts.Add( "step" );
                alts.Add( "STP" );
                alts.Add( "STEP" );
                alts.Add( "Stp" );
                alts.Add( "Step" );

                // IGES files
                alts.Add( "iges" );
                alts.Add( "IGES" );
                alts.Add( "igs" );
                alts.Add( "IGS" );

                //TODO - Other alternative formats?

                for( auto alt : alts )
                {
                    wxFileName altFile( basePath, baseName + "." + alt );

                    if( altFile.IsOk() && altFile.FileExists() )
                    {
                        std::string altFileName = altFile.GetFullPath().ToStdString();

                        if( getModelLabel( altFileName, aLabel ) )
                        {
                            return true;
                        }
                    }
                }
            }

            break;

        // TODO: implement IDF and EMN converters

        default:
            return false;
    }

    aLabel = transferModel( doc, m_doc );

    if( aLabel.IsNull() )
    {
        std::ostringstream ostr;
#ifdef __WXDEBUG__
        ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
#endif /* __WXDEBUG */
        ostr << "  * could not transfer model data from file '" << aFileName << "'\n";
        wxLogMessage( "%s", ostr.str().c_str() );
        return false;
    }

    // attach the PART NAME ( base filename: note that in principle
    // different models may have the same base filename )
    wxFileName afile( aFileName.c_str() );
    std::string pname( afile.GetName().ToUTF8() );
    TCollection_ExtendedString partname( pname.c_str() );
    TDataStd_Name::Set( aLabel, partname );

    m_models.insert( MODEL_DATUM( aFileName, aLabel ) );
    ++m_components;
    return true;
}