~pierre-parent-k/kicad/length-tunning

« back to all changes in this revision

Viewing changes to pcbnew/cross-probing.cpp

  • Committer: Pierre Parent
  • Date: 2014-07-06 10:32:13 UTC
  • mfrom: (4798.1.179 kicad)
  • Revision ID: pierre.parent@insa-rouen.fr-20140706103213-wjsdy0hc9q6wbz5v
Merge with lp:kicad 4977

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
 
13
13
#include <fctsys.h>
14
14
#include <pgm_base.h>
 
15
#include <kiface_i.h>
 
16
#include <kiway_express.h>
15
17
#include <wxPcbStruct.h>
16
18
#include <eda_dde.h>
17
19
#include <macros.h>
130
132
}
131
133
 
132
134
 
 
135
std::string FormatProbeItem( BOARD_ITEM* aItem )
 
136
{
 
137
    MODULE*     module;
 
138
 
 
139
    switch( aItem->Type() )
 
140
    {
 
141
    case PCB_MODULE_T:
 
142
        module = (MODULE*) aItem;
 
143
        return StrPrintf( "$PART: \"%s\"", TO_UTF8( module->GetReference() ) );
 
144
 
 
145
    case PCB_PAD_T:
 
146
        {
 
147
            module = (MODULE*) aItem->GetParent();
 
148
            wxString pad = ((D_PAD*)aItem)->GetPadName();
 
149
 
 
150
            return StrPrintf( "$PART: \"%s\" $PAD: \"%s\"",
 
151
                     TO_UTF8( module->GetReference() ),
 
152
                     TO_UTF8( pad ) );
 
153
        }
 
154
 
 
155
    case PCB_MODULE_TEXT_T:
 
156
        {
 
157
            module = (MODULE*) aItem->GetParent();
 
158
 
 
159
            TEXTE_MODULE*   text_mod = (TEXTE_MODULE*) aItem;
 
160
 
 
161
            const char*     text_key;
 
162
 
 
163
            if( text_mod->GetType() == TEXTE_MODULE::TEXT_is_REFERENCE )
 
164
                text_key = "$REF:";
 
165
            else if( text_mod->GetType() == TEXTE_MODULE::TEXT_is_VALUE )
 
166
                text_key = "$VAL:";
 
167
            else
 
168
                break;
 
169
 
 
170
            return StrPrintf( "$PART: \"%s\" %s \"%s\"",
 
171
                     TO_UTF8( module->GetReference() ),
 
172
                     text_key,
 
173
                     TO_UTF8( text_mod->GetText() ) );
 
174
        }
 
175
 
 
176
    default:
 
177
        break;
 
178
    }
 
179
 
 
180
    return "";
 
181
}
 
182
 
 
183
 
133
184
/**
134
185
 * Send a remote command to Eeschema via a socket,
135
186
 * @param objectToSync = item to be located on schematic (module, pin or text)
139
190
 * $PART: "reference" $REF: "reference" put cursor on the component ref
140
191
 * $PART: "reference" $VAL: "value" put cursor on the component value
141
192
 */
142
 
void PCB_EDIT_FRAME::SendMessageToEESCHEMA( BOARD_ITEM* objectToSync )
 
193
void PCB_EDIT_FRAME::SendMessageToEESCHEMA( BOARD_ITEM* aSyncItem )
143
194
{
144
 
    char          cmd[1024];
145
 
    const char*   text_key;
146
 
    MODULE*       module = NULL;
147
 
    D_PAD*        pad;
148
 
    TEXTE_MODULE* text_mod;
149
 
    wxString      msg;
150
 
 
151
 
    if( objectToSync == NULL )
 
195
#if 1
 
196
    wxASSERT( aSyncItem );      // can't we fix the caller?
 
197
#else
 
198
    if( !aSyncItem )
152
199
        return;
153
 
 
154
 
    switch( objectToSync->Type() )
 
200
#endif
 
201
 
 
202
    std::string packet = FormatProbeItem( aSyncItem );
 
203
 
 
204
    if( packet.size() )
155
205
    {
156
 
    case PCB_MODULE_T:
157
 
        module = (MODULE*) objectToSync;
158
 
        sprintf( cmd, "$PART: \"%s\"", TO_UTF8( module->GetReference() ) );
159
 
        break;
160
 
 
161
 
    case PCB_PAD_T:
162
 
        module = (MODULE*) objectToSync->GetParent();
163
 
        pad    = (D_PAD*) objectToSync;
164
 
        msg    = pad->GetPadName();
165
 
        sprintf( cmd, "$PART: \"%s\" $PAD: \"%s\"",
166
 
                 TO_UTF8( module->GetReference() ),
167
 
                 TO_UTF8( msg ) );
168
 
        break;
169
 
 
170
 
    case PCB_MODULE_TEXT_T:
171
 
        module   = (MODULE*) objectToSync->GetParent();
172
 
        text_mod = (TEXTE_MODULE*) objectToSync;
173
 
 
174
 
        if( text_mod->GetType() == TEXTE_MODULE::TEXT_is_REFERENCE )
175
 
            text_key = "$REF:";
176
 
        else if( text_mod->GetType() == TEXTE_MODULE::TEXT_is_VALUE )
177
 
            text_key = "$VAL:";
 
206
        if( Kiface().IsSingle() )
 
207
            SendCommand( MSG_TO_SCH, packet.c_str() );
178
208
        else
179
 
            break;
180
 
 
181
 
        sprintf( cmd, "$PART: \"%s\" %s \"%s\"",
182
 
                 TO_UTF8( module->GetReference() ),
183
 
                 text_key,
184
 
                 TO_UTF8( text_mod->GetText() ) );
185
 
        break;
186
 
 
187
 
    default:
188
 
        break;
 
209
        {
 
210
            // Typically ExpressMail is going to be s-expression packets, but since
 
211
            // we have existing interpreter of the cross probe packet on the other
 
212
            // side in place, we use that here.
 
213
            Kiway().ExpressMail( FRAME_SCH, MAIL_CROSS_PROBE, packet, this );
 
214
        }
189
215
    }
190
 
 
191
 
    if( module )
 
216
}
 
217
 
 
218
 
 
219
void PCB_EDIT_FRAME::KiwayMailIn( KIWAY_EXPRESS& mail )
 
220
{
 
221
    const std::string& payload = mail.GetPayload();
 
222
 
 
223
    switch( mail.Command() )
192
224
    {
193
 
        SendCommand( MSG_TO_SCH, cmd );
 
225
    case MAIL_CROSS_PROBE:
 
226
        ExecuteRemoteCommand( payload.c_str() );
 
227
        break;
 
228
 
 
229
    // many many others.
 
230
 
194
231
    }
195
232
}
 
233