Esempio n. 1
0
File: erc.cpp Progetto: natsfr/kicad
void TestLabel( NETLIST_OBJECT_LIST* aList, unsigned aNetItemRef, unsigned aStartNet )
{
    unsigned netItemTst = aStartNet;
    int      erc = 1;

    /* Review the list of labels connected to NetItemRef. */
    for( ; ; netItemTst++ )
    {
        if( netItemTst == aNetItemRef )
            continue;

        /* Is always in the same net? */
        if( ( netItemTst == aList->size() )
          || ( aList->GetItemNet( aNetItemRef ) != aList->GetItemNet( netItemTst ) ) )
        {
            /* End Netcode found. */
            if( erc )
            {
                /* Glabel or SheetLabel orphaned. */
                Diagnose( aList->GetItem( aNetItemRef ), NULL, -1, WAR );
            }

            return;
        }

        if( aList->GetItem( aNetItemRef )->IsLabelConnected( aList->GetItem( netItemTst ) ) )
            erc = 0;

        //same thing, different order.
        if( aList->GetItem( netItemTst )->IsLabelConnected( aList->GetItem( aNetItemRef ) ) )
            erc = 0;
    }
}
Esempio n. 2
0
int Gen3D::compute(const char *)
{
   int i;

   isset = 0;

   if(Diagnose()<0)
      return FAIL;

   int numVelos=0;
   int numGeos=0;
   int numPress=0;

   float *xCoords,*yCoords,*zCoords;
   float *xCoordsIn,*yCoordsIn,*zCoordsIn;

   float *uIn, *vIn, *wIn;

   int *plist,*clist,*vlist,*tlist;
   int no_pl,no_vl,no_points;

   if (isset)
   {

   }
   else                                           // (isset=0)
   {
      polyIn = (coDoPolygons *)p_inPoly->getCurrentObject();

      no_pl = polyIn->getNumPolygons();
      no_vl = polyIn->getNumVertices();
      no_points = polyIn->getNumPoints();

      polyIn->getAddresses(&xCoordsIn,&yCoordsIn,&zCoordsIn,&clist,&plist);

      int nelem = no_pl;
      int nconn = 8*no_pl;
      int ncoord = 2*no_points;

      int *elem;
      int *conn;

      gridOutObj = new coDoUnstructuredGrid(p_outGrid->getObjName(),nelem,nconn,ncoord,1);
      gridOutObj->getAddresses(&elem,&conn,&xCoords,&yCoords,&zCoords);
      gridOutObj->getTypeList(&tlist);

      for(i=0;i<no_pl;i++)
      {
         tlist[i]=TYPE_HEXAGON;
      }

      // element list is easy as we just have hexas ...
      for(i=0;i<no_pl;i++)
      {
         elem[i] = 8*i;
      }

      // connectivity list made of corner list
      for(i=0;i<no_pl;i++)
      {
         conn[8*i+0] = clist[plist[i]+0];
         conn[8*i+1] = clist[plist[i]+1];
         conn[8*i+2] = clist[plist[i]+2];
         conn[8*i+3] = clist[plist[i]+3];
         conn[8*i+4] = clist[plist[i]+0]+no_points;
         conn[8*i+5] = clist[plist[i]+1]+no_points;
         conn[8*i+6] = clist[plist[i]+2]+no_points;
         conn[8*i+7] = clist[plist[i]+3]+no_points;
      }

      // the coordinate list is easy as soon as we know in which direction to expand ...

      // to find out in which coordinate plain (XY, XZ, YZ) the 2D grid lies in,
      // we get a normal vector in the first element
      float x1,x2,x3,y1,y2,y3,z1,z2,z3,nx,ny,nz;
      x1 = xCoordsIn[0]; y1 = xCoordsIn[0]; z1 = zCoordsIn[0];
      x2 = xCoordsIn[1]; y2 = xCoordsIn[1]; z2 = zCoordsIn[1];
      x3 = xCoordsIn[2]; y3 = xCoordsIn[2]; z3 = zCoordsIn[2];
      nx = (fabs) ( 1000*(y2-y1)*(z3-z1)-1000*(z2-z1)*(y3-y1) );
      ny = (fabs) ( 1000*(z2-z1)*(x3-x1)-1000*(x2-x1)*(z3-z1) );
      nz = (fabs) ( 1000*(x2-x1)*(y3-y1)-1000*(y2-y1)*(x3-x1) );

      float min = FLT_MAX;
      int min_axis[3] = {0,0,0};
      if (nx<min)
      {
         min_axis[0]=1;
         min_axis[1]=0;
         min_axis[2]=0;
      }
      if (ny<min)
      {
         min_axis[0]=0;
         min_axis[1]=1;
         min_axis[2]=0;
      }
      if (nz<min)
      {
         min_axis[0]=0;
         min_axis[1]=0;
         min_axis[2]=1;
      }

      // we'd like to have a XY-grid, so we exchange the corrdinates ...
      float *tmp;
      if (min_axis[0]==1)                         //YZ
      {
         tmp=xCoordsIn;
         xCoordsIn=zCoordsIn;
         zCoordsIn=tmp;
      }

      if (min_axis[1]==1)                         //XZ
      {
         tmp=yCoordsIn;
         yCoordsIn=zCoordsIn;
         zCoordsIn=tmp;
      }

      float delta = p_thick->getValue();
      for(i=0;i<no_points;i++)
      {
         zCoords[i]=zCoordsIn[i]-min_axis[2]*delta/2.;
         zCoords[i+no_points]=zCoordsIn[i]+min_axis[2]*delta/2.;

         yCoords[i]=yCoordsIn[i]-min_axis[1]*delta/2.;
         yCoords[i+no_points]=yCoordsIn[i]+min_axis[1]*delta/2.;

         xCoords[i]=xCoordsIn[i]-min_axis[0]*delta/2.;
         xCoords[i+no_points]=xCoordsIn[i]-min_axis[0]*delta/2.;
      }

      p_outGrid->setCurrentObject(gridOutObj);

      // velocity

      veloInObj = (coDoVec3 *)p_inVelo->getCurrentObject();
      no_points = veloInObj->getNumPoints();

      // change of axis to xy!
      veloInObj->getAddresses(&uIn,&vIn,&wIn);

      float *uOut = new float[2*no_points];
      float *vOut = new float[2*no_points];
      float *wOut = new float[2*no_points];

      if (min_axis[0]==1)                         //YZ
      {
         tmp=uIn;
         uIn=wIn;
         wIn=tmp;
      }

      if (min_axis[1]==1)                         //XZ
      {
         tmp=vIn;
         vIn=wIn;
         wIn=tmp;
      }

      for (i=0;i<no_points;i++)
      {
         uOut[i]=uIn[i];
         uOut[i+no_points]=uIn[i];

         vOut[i]=vIn[i];
         vOut[i+no_points]=vIn[i];

         wOut[i]=wIn[i];
         wOut[i+no_points]=wIn[i];
      }

      veloOutObj = new coDoVec3(p_outVelo->getObjName(),2*no_points,uOut,vOut,wOut);
      p_outVelo->setCurrentObject(veloOutObj);

   }

   return SUCCESS;

}
void DIALOG_ERC::TestErc( wxArrayString* aMessagesList )
{
    wxFileName fn;

    m_writeErcFile = m_WriteResultOpt->GetValue();
    m_TestSimilarLabels = m_cbTestSimilarLabels->GetValue();
    m_tstUniqueGlobalLabels = m_cbTestUniqueGlbLabels->GetValue();

    // Build the whole sheet list in hierarchy (sheet, not screen)
    SCH_SHEET_LIST sheets;
    sheets.AnnotatePowerSymbols( Prj().SchLibs() );

    if( m_parent->CheckAnnotate( aMessagesList, false ) )
    {
        if( aMessagesList )
        {
            wxString msg = _( "Annotation required!" );
            msg += wxT( "\n" );
            aMessagesList->Add( msg );
        }

        return;
    }

    SCH_SCREENS screens;

    // Erase all previous DRC markers.
    screens.DeleteAllMarkers( MARKER_BASE::MARKER_ERC );

    for( SCH_SCREEN* screen = screens.GetFirst(); screen != NULL; screen = screens.GetNext() )
    {
        /* Ff wire list has changed, delete Undo Redo list to avoid pointers on deleted
         * data problems.
         */
        if( screen->SchematicCleanUp( NULL ) )
            screen->ClearUndoRedoList();
    }

    /* Test duplicate sheet names inside a given sheet, one cannot have sheets with
     * duplicate names (file names can be duplicated).
     */
    TestDuplicateSheetNames( true );

    std::auto_ptr<NETLIST_OBJECT_LIST> objectsConnectedList( m_parent->BuildNetListBase() );

    // Reset the connection type indicator
    objectsConnectedList->ResetConnectionsType();

    unsigned lastNet;
    unsigned nextNet = lastNet = 0;
    int MinConn    = NOC;

    for( unsigned net = 0; net < objectsConnectedList->size(); net++ )
    {
        if( objectsConnectedList->GetItemNet( lastNet ) !=
            objectsConnectedList->GetItemNet( net ) )
        {
            // New net found:
            MinConn    = NOC;
            nextNet   = net;
        }

        switch( objectsConnectedList->GetItemType( net ) )
        {
        // These items do not create erc problems
        case NET_ITEM_UNSPECIFIED:
        case NET_SEGMENT:
        case NET_BUS:
        case NET_JUNCTION:
        case NET_LABEL:
        case NET_BUSLABELMEMBER:
        case NET_PINLABEL:
        case NET_GLOBBUSLABELMEMBER:
            break;

        case NET_HIERLABEL:
        case NET_HIERBUSLABELMEMBER:
        case NET_SHEETLABEL:
        case NET_SHEETBUSLABELMEMBER:
            // ERC problems when pin sheets do not match hierarchical labels.
            // Each pin sheet must match a hierarchical label
            // Each hierarchical label must match a pin sheet
            objectsConnectedList->TestforNonOrphanLabel( net, nextNet );
            break;
        case NET_GLOBLABEL:
            if( m_tstUniqueGlobalLabels )
                objectsConnectedList->TestforNonOrphanLabel( net, nextNet );
            break;

        case NET_NOCONNECT:

            // ERC problems when a noconnect symbol is connected to more than one pin.
            MinConn = NET_NC;

            if( objectsConnectedList->CountPinsInNet( nextNet ) > 1 )
                Diagnose( objectsConnectedList->GetItem( net ), NULL, MinConn, UNC );

            break;

        case NET_PIN:

            // Look for ERC problems between pins:
            TestOthersItems( objectsConnectedList.get(), net, nextNet, &MinConn );
            break;
        }

        lastNet = net;
    }

    // Test similar labels (i;e. labels which are identical when
    // using case insensitive comparisons)
    if( m_TestSimilarLabels )
        objectsConnectedList->TestforSimilarLabels();

    // Displays global results:
    updateMarkerCounts( &screens );

    // Display diags:
    DisplayERC_MarkersList();

    // Display new markers:
    m_parent->GetCanvas()->Refresh();

    if( m_writeErcFile )
    {
        fn = g_RootSheet->GetScreen()->GetFileName();
        fn.SetExt( wxT( "erc" ) );

        wxFileDialog dlg( this, _( "ERC File" ), fn.GetPath(), fn.GetFullName(),
                          _( "Electronic rule check file (.erc)|*.erc" ),
                          wxFD_SAVE );

        if( dlg.ShowModal() == wxID_CANCEL )
            return;

        if( WriteDiagnosticERC( dlg.GetPath() ) )
        {
            Close( true );
            ExecuteFile( this, Pgm().GetEditorName(), QuoteFullPath( fn ) );
        }
    }
}
Esempio n. 4
0
VOID
DigiDPCService( IN PKDPC Dpc,
                IN PVOID DeferredContext,
                IN PVOID SystemContext1,
                IN PVOID SystemContext2 )
{
   extern BOOLEAN DigiDriverInitialized; // from init.c
   PDIGI_CONTROLLER_EXTENSION ControllerExt = DeferredContext;

   DigiDump( DIGIDPCFLOW, ("DigiBoard: Entering DigiDPCService\n") );

   // Ensure the controller is intialized.
   if( DigiDriverInitialized  // We can't get here if we're not initialized. --SWA
   &&  ControllerExt->ControllerState == DIGI_DEVICE_STATE_INITIALIZED )
   {
      USHORT DownloadRequest, FepStat;
      USHORT Ein, Eout;

      EnableWindow( ControllerExt, ControllerExt->Global.Window );

      FepStat =
         READ_REGISTER_USHORT( (PUSHORT)((PUCHAR)ControllerExt->VirtualAddress+
                                          FEP_FEPSTAT) );
      DownloadRequest =
         READ_REGISTER_USHORT( (PUSHORT)((PUCHAR)ControllerExt->VirtualAddress+
                                          FEP_DLREQ) );
      Ein =
         READ_REGISTER_USHORT( (PUSHORT)((PUCHAR)ControllerExt->VirtualAddress+
                                          FEP_EIN) );
      Eout =
         READ_REGISTER_USHORT( (PUSHORT)((PUCHAR)ControllerExt->VirtualAddress+
                                          FEP_EOUT) );

      DisableWindow( ControllerExt );

      if (FepStat!=FEP_FEPSTAT_OK)
      {
         LARGE_INTEGER CurrentSystemTime;

         KeQuerySystemTime( &CurrentSystemTime );
         InterlockedIncrement(&ControllerExt->WindowFailureCount);

         DigiDump( DIGIERRORS, ("DigiBoard: Memory Window Failure (%d)\n", ControllerExt->WindowFailureCount));

         if (CurrentSystemTime.HighPart!=ControllerExt->LastErrorLogTime.HighPart)
         {
            PHYSICAL_ADDRESS Signature;

            Signature.LowPart = 0x5a5a5a5a;
            ControllerExt->LastErrorLogTime = CurrentSystemTime;
            DigiLogError( ControllerExt->DriverObject,
                          NULL,
                          Diagnose(ControllerExt),
                          Signature,
                          0,
                          0,
                          (UCHAR)ControllerExt->WindowFailureCount,
                          __LINE__,
                          STATUS_SUCCESS,
                          SERIAL_MEMORY_WINDOW_FAILURE,
                          ControllerExt->ControllerName.Length+1,
                          ControllerExt->ControllerName.Buffer,
                          0,
                          NULL );
         }
      }
      else if( DownloadRequest ) // Look and see if there is a download request
      {
         // The Controller is requesting a concentrator download.

         XXDownload( ControllerExt );

         //
         // We don't service any ports until all concentrator
         // requests have been satisfied.
         //
      }
      else if( Ein != Eout )
      {
         //
         // Architecture ensures we have exclusive access to events on the controller.
         // (We reschedule ourselves to run, so two instances cannot coexist.)
         //
         DigiServiceEvent( ControllerExt, Ein, Eout );
      }

   }

   // Reset our timer.
   KeSetTimer( &ControllerExt->PollTimer,
               ControllerExt->PollTimerLength,
               &ControllerExt->PollDpc );

   DigiDump( DIGIDPCFLOW, ("DigiBoard: Exiting DigiDPCService\n") );

}  // DigiDPCService
Esempio n. 5
0
File: erc.cpp Progetto: natsfr/kicad
void TestOthersItems( NETLIST_OBJECT_LIST* aList,
                      unsigned aNetItemRef, unsigned aNetStart,
                      int* aNetNbItems, int* aMinConnexion )
{
    unsigned netItemTst = aNetStart;
    int jj;
    int erc = OK;

    /* Analysis of the table of connections. */
    int ref_elect_type = aList->GetItem( aNetItemRef )->m_ElectricalType;
    int local_minconn = NOC;

    if( ref_elect_type == PIN_NC )
        local_minconn = NPI;

    /* Test pins connected to NetItemRef */
    for( ; ; netItemTst++ )
    {
        if( aNetItemRef == netItemTst )
            continue;

        // We examine only a given net. We stop the search if the net changes
        if( ( netItemTst >= aList->size() ) // End of list
            || ( aList->GetItemNet( aNetItemRef ) !=
                 aList->GetItemNet( netItemTst ) ) ) // End of net
        {
            /* End net code found: minimum connection test. */
            if( ( *aMinConnexion < NET_NC ) && ( local_minconn < NET_NC ) )
            {
                /* Not connected or not driven pin. */
                bool seterr = true;

                if( local_minconn == NOC &&
                    aList->GetItemType( aNetItemRef ) == NET_PIN )
                {
                    /* This pin is not connected: for multiple part per
                     * package, and duplicated pin,
                     * search for an other instance of this pin
                     * this will be flagged only if all instances of this pin
                     * are not connected
                     * TODO test also if instances connected are connected to
                     * the same net
                     */
                    for( unsigned duplicate = 0; duplicate < aList->size(); duplicate++ )
                    {
                        if( aList->GetItemType( duplicate ) != NET_PIN )
                            continue;

                        if( duplicate == aNetItemRef )
                            continue;

                        if( aList->GetItem( aNetItemRef )->m_PinNum !=
                            aList->GetItem( duplicate )->m_PinNum )
                            continue;

                        if( ( (SCH_COMPONENT*) aList->GetItem( aNetItemRef )->
                             m_Link )->GetRef( &aList->GetItem( aNetItemRef )-> m_SheetPath ) !=
                            ( (SCH_COMPONENT*) aList->GetItem( duplicate )->m_Link )
                           ->GetRef( &aList->GetItem( duplicate )->m_SheetPath ) )
                            continue;

                        // Same component and same pin. Do dot create error for this pin
                        // if the other pin is connected (i.e. if duplicate net has an other
                        // item)
                        if( (duplicate > 0)
                          && ( aList->GetItemNet( duplicate ) ==
                               aList->GetItemNet( duplicate - 1 ) ) )
                            seterr = false;

                        if( (duplicate < aList->size() - 1)
                          && ( aList->GetItemNet( duplicate ) ==
                               aList->GetItemNet( duplicate + 1 ) ) )
                            seterr = false;
                    }
                }

                if( seterr )
                    Diagnose( aList->GetItem( aNetItemRef ), NULL, local_minconn, WAR );

                *aMinConnexion = DRV;   // inhibiting other messages of this
                                       // type for the net.
            }
            return;
        }

        switch( aList->GetItemType( netItemTst ) )
        {
        case NET_ITEM_UNSPECIFIED:
        case NET_SEGMENT:
        case NET_BUS:
        case NET_JUNCTION:
        case NET_LABEL:
        case NET_HIERLABEL:
        case NET_BUSLABELMEMBER:
        case NET_HIERBUSLABELMEMBER:
        case NET_SHEETBUSLABELMEMBER:
        case NET_SHEETLABEL:
        case NET_GLOBLABEL:
        case NET_GLOBBUSLABELMEMBER:
        case NET_PINLABEL:
            break;

        case NET_NOCONNECT:
            local_minconn = std::max( NET_NC, local_minconn );
            break;

        case NET_PIN:
            jj = aList->GetItem( netItemTst )->m_ElectricalType;
            local_minconn = std::max( MinimalReq[ref_elect_type][jj], local_minconn );

            if( netItemTst <= aNetItemRef )
                break;

            *aNetNbItems += 1;

            if( erc == OK )
            {
                erc = DiagErc[ref_elect_type][jj];

                if( erc != OK )
                {
                    if( aList->GetConnectionType( netItemTst ) == UNCONNECTED )
                    {
                        Diagnose( aList->GetItem( aNetItemRef ),
                                  aList->GetItem( netItemTst ),
                                  0, erc );
                        aList->SetConnectionType( netItemTst, NOCONNECT_SYMBOL_PRESENT );
                    }
                }
            }

            break;
        }
    }
}
Esempio n. 6
0
int
Sample::compute(const char *)
{
    int x_value, y_value, z_value;
    int s;
    bool nan_flag = false; //TODO: Is this the right default-value?
    float fill = .0; //TODO: Is this the right default-value?
    int outside;

    const char *object_type = NULL;

    unstruct_grid::vecFlag typeFlag = unstruct_grid::DONTKNOW;

    ias grids;
    ias data;
    grids.resize(1);
    data.resize(1);

    eps = epsParam->getValue();
    if (eps < 0.0)
    {
        sendError("eps < 0.0 not allowed - please choose a valid eps");
        return FAIL;
    }

    s = iSizeChoiceParam->getValue() + 1;
    if (s == 1)
    {
        x_value = iSizeParam->getValue();
    }
    else
    {
        x_value = 2 << s;
    }

    s = jSizeChoiceParam->getValue() + 1;
    if (s == 1)
    {
        y_value = jSizeParam->getValue();
    }
    else
    {
        y_value = 2 << s;
    }

    s = kSizeChoiceParam->getValue() + 1;
    if (s == 1)
    {
        z_value = kSizeParam->getValue();
    }
    else
    {
        z_value = 2 << s;
    }

    if (x_value < 2)
    {
        sendWarning("Size in X dimension is less than 2, assuming 2");
        iSizeParam->setValue(2);
        x_value = 2;
    }
    if (y_value < 2)
    {
        sendWarning("Size in Y dimension is less than 2, assuming 2");
        jSizeParam->setValue(2);
        y_value = 2;
    }
    if (z_value < 2)
    {
        sendWarning("Size in Z dimension is less than 2, assuming 2");
        kSizeParam->setValue(2);
        z_value = 2;
    }

    outside = outsideChoiceParam->getValue();
    if (outside == Sample::OUTSIDE_MAX_FLT)
    {
        nan_flag = true;
    }
    else if (outside == Sample::OUTSIDE_NUMBER)
    {

        fill = fillValueParam->getValue();
        nan_flag = false;
    }

    bool isStrGrid = false;
    // here we try to retrieve the data object from the required port
    const coDistributedObject *GridObj = Grid_In_Port->getCurrentObject();
    TimeSteps = 0;
    if (!GridObj)
    {
        sendError("cannot retrieve the grid object");
        return FAIL;
    }
    else if (strcmp(GridObj->getType(), "SETELE") == 0)
    {
        // Time Steps or not...
        const coDoSet *setGrid = (const coDoSet *)(GridObj);
        gridTimeSteps = setGrid->getAllElements(&num_set_ele);
        if (GridObj->getAttribute("TIMESTEP"))
        {
            // We have timesteps
            TimeSteps = 1;
            gridTimeSteps = setGrid->getAllElements(&num_set_ele);
            grids.resize(num_set_ele);
            data.resize(num_set_ele);
            for (int time = 0; time < num_set_ele; ++time)
            {
                if (gridTimeSteps[time]->isType("SETELE"))
                {
                    // extract list from the set gridTimeSteps[time]
                    const coDistributedObject *const *elemsInGridTimeSteps;
                    int numInGridTimeSteps;
                    elemsInGridTimeSteps = ((coDoSet *)(gridTimeSteps[time]))->getAllElements(&numInGridTimeSteps);
                    //ExpandSetList (elemsInGridTimeSteps, numInGridTimeSteps, "UNSGRD", grids[time]);
                    ExpandSetList(elemsInGridTimeSteps, numInGridTimeSteps, &object_type, grids[time]);
                }
                else if (!object_type)
                {
                    if (gridTimeSteps[time]->isType("POINTS")
                        || gridTimeSteps[time]->isType("UNSGRD")
                        || gridTimeSteps[time]->isType("UNIGRD")
                        || gridTimeSteps[time]->isType("RCTGRD")
                        || gridTimeSteps[time]->isType("STRGRD"))
                    {
                        object_type = gridTimeSteps[time]->getType();
                        grids[time].resize(1);
                        grids[time][0] = gridTimeSteps[time];
                    }
                    else
                    {
                        // Strange object in the grid object
                        sendError("Objects in the grid object have to be sets, unstructured grids or points");
                        return FAIL;
                    }
                }
                else if (strcmp(gridTimeSteps[time]->getType(), object_type) == 0)
                {
                    grids[time].resize(1);
                    grids[time][0] = gridTimeSteps[time];
                }
                else
                {
                    // Strange object in the grid object
                    sendError("Objects in the grid object have to be sets, unstructured grids or points");
                    return FAIL;
                }
            }
            if (object_type && (!strcmp(object_type, "UNIGRD") || !strcmp(object_type, "RCTGRD") || !strcmp(object_type, "STRGRD")))
            {
                isStrGrid = true;
            }
        }
        else
        {
            // Static grid
            // We may set up grids
            num_blocks = ExpandSetList(gridTimeSteps, num_set_ele, &object_type, grids[0]);
            if (!object_type || (strcmp(object_type, "UNSGRD") != 0
                                 && strcmp(object_type, "POINTS") != 0
                                 && strcmp(object_type, "UNIGRD") != 0
                                 && strcmp(object_type, "RCTGRD") != 0
                                 && strcmp(object_type, "STRGRD") != 0))
            {
                // Strange object in the grid object
                sendError("Objects in the grid object have to be sets, unstructured grids or points");
                return FAIL;
            }
        }
    }
    else if (strcmp(GridObj->getType(), "UNSGRD") == 0)
    {
        object_type = "UNSGRD";
        num_blocks = 1;
        grids[0].push_back(GridObj);
    }
    else if (strcmp(GridObj->getType(), "UNIGRD") == 0)
    {
        object_type = "UNIGRD";
        num_blocks = 1;
        grids[0].push_back(GridObj);
        isStrGrid = true;
    }
    else if (strcmp(GridObj->getType(), "RCTGRD") == 0)
    {
        object_type = "RCTGRD";
        num_blocks = 1;
        grids[0].push_back(GridObj);
        isStrGrid = true;
    }
    else if (strcmp(GridObj->getType(), "STRGRD") == 0)
    {
        object_type = "STRGRD";
        num_blocks = 1;
        grids[0].push_back(GridObj);
        isStrGrid = true;
    }
    else if (strcmp(GridObj->getType(), "POINTS") == 0)
    {
        object_type = "POINTS";
        num_blocks = 1;
        grids[0].push_back(GridObj);
    }
    else
    {
        sendError("Sorry, only objects of type unstructured grid or points are supported");
        return FAIL;
    }

    fprintf(stderr, "isStrGrid=%d, type=%s\n", int(isStrGrid), object_type);

    if (!object_type)
    {
        sendError("Sorry, only objects of type unstructured grid or points are supported");
        return FAIL;
    }

    if (strcmp(object_type, "POINTS") == 0)
    {
        typeFlag = unstruct_grid::POINT;
    }

    // here we try to retrieve the data object from the port
    const coDistributedObject *DataObj = Data_In_Port->getCurrentObject();
    if (!DataObj)
    {
        cerr << "data: NULL" << endl;
        if (typeFlag != unstruct_grid::POINT)
        {
            sendError("cannot retrieve data object");
            return FAIL;
        }
    }
    else if (strcmp(DataObj->getType(), "SETELE") == 0)
    {
        // Time Steps or not...: that is decided according to the grid.
        if (strcmp(GridObj->getType(), "SETELE") != 0)
        {
            sendError("Grid object is a set, but not the data");
            return FAIL;
        }
        int data_num_set_ele;
        int data_num_blocks;
        coDoSet *setData = (coDoSet *)(DataObj);
        dataTimeSteps = setData->getAllElements(&data_num_set_ele);
        if (TimeSteps)
        {
            // We have timesteps
            if (data_num_set_ele != num_set_ele)
            {
                sendError("Number of time steps in grid does not match data set");
                return FAIL;
            }
            for (int time = 0; time < num_set_ele; ++time)
            {
                if (strcmp(dataTimeSteps[time]->getType(), "SETELE") == 0)
                {
                    // extract list from the set gridTimeSteps[time]
                    int numInDataTimeSteps;
                    const coDistributedObject *const *elemsInDataTimeSteps = ((coDoSet *)(dataTimeSteps[time]))->getAllElements(&numInDataTimeSteps);
                    const char *type = NULL;
                    int num_data = ExpandSetList(elemsInDataTimeSteps, numInDataTimeSteps, &type, data[time]);
                    if (!type)
                    {
                        sendError("Invalid data");
                        return FAIL;
                    }

                    if (num_data != grids[time].size())
                    {
                        sendError("Cannot match grids and data sets -- data must be node based");
                        return FAIL;
                    }

                    // try first vector
                    if (strcmp(type, "USTVDT") == 0)
                    {
                        if (typeFlag == unstruct_grid::DONTKNOW)
                        {
                            typeFlag = unstruct_grid::VECTOR;
                        }
                        else
                        {
                            sendError("Cannot decide between vector, scalar, and point");
                            return FAIL;
                        }
                    }
                    // then try scalar
                    else if (strcmp(type, "USTSDT") == 0)
                    {
                        if (typeFlag == unstruct_grid::DONTKNOW)
                        {
                            typeFlag = unstruct_grid::SCALAR;
                        }
                        else
                        {
                            sendError("Cannot decide between vector, scalar, and point");
                            return FAIL;
                        }
                    }
                    else if (strcmp(type, "POINTS") == 0)
                    {
                        if (typeFlag == unstruct_grid::DONTKNOW)
                        {
                            typeFlag = unstruct_grid::POINT;
                        }
                        else
                        {
                            sendError("Cannot decide between vector, scalar, and point");
                            return FAIL;
                        }
                    }
                    else
                    {
                        sendError("Invalid data type");
                        return FAIL;
                    }
                }
                else if (strcmp(dataTimeSteps[time]->getType(), "USTSDT") == 0)
                {
                    data[time].resize(1);
                    data[time][0] = dataTimeSteps[time];
                    if (typeFlag == unstruct_grid::DONTKNOW)
                    {
                        typeFlag = unstruct_grid::SCALAR;
                    }
                    else if (typeFlag == unstruct_grid::VECTOR)
                    {
                        sendError("Cannot decide between vector and scalar");
                        return FAIL;
                    }
                }
                else if (strcmp(dataTimeSteps[time]->getType(), "USTVDT") == 0)
                {
                    data[time].resize(1);
                    data[time][0] = dataTimeSteps[time];
                    if (typeFlag == unstruct_grid::DONTKNOW)
                    {
                        typeFlag = unstruct_grid::VECTOR;
                    }
                    else if (typeFlag != unstruct_grid::VECTOR)
                    {
                        sendError("Cannot decide between vector and scalar");
                        return FAIL;
                    }
                }
                else if (strcmp(dataTimeSteps[time]->getType(), "POINTS") == 0)
                {
                    data[time].resize(1);
                    data[time][0] = dataTimeSteps[time];
                    if (typeFlag == unstruct_grid::DONTKNOW)
                    {
                        typeFlag = unstruct_grid::POINT;
                    }
                    else if (typeFlag != unstruct_grid::POINT)
                    {
                        sendError("Cannot decide between vector, scalar and point");
                        return FAIL;
                    }
                }
                else
                {
                    sendError("Object of incorrect type in data set");
                    return FAIL;
                }
            }
        } // static set... set up data
        else
        {
            const char *type = NULL;
            data_num_blocks = ExpandSetList(dataTimeSteps, data_num_set_ele, &type, data[0]);
            if (!type)
            {
                sendError("Invalid data");
                return FAIL;
            }

            if (data_num_blocks != num_blocks)
            {
                sendError("Grid and data sets do not match for the accepted types");
                return FAIL;
            }

            if (typeFlag == unstruct_grid::DONTKNOW)
            {
                if (strcmp(type, "USTSDT") == 0)
                {
                    typeFlag = unstruct_grid::SCALAR;
                }
                else if (strcmp(type, "USTVDT") == 0)
                {
                    typeFlag = unstruct_grid::VECTOR;
                }
                else if (strcmp(type, "POINTS") == 0)
                {
                    typeFlag = unstruct_grid::POINT;
                }
                else
                {
                    sendError("Invalid data type");
                    return FAIL;
                }
            }
        }
    }
    else if (strcmp(DataObj->getType(), "USTSDT") == 0)
    {
        data[0].resize(1);
        data[0][0] = (DataObj);
        if (typeFlag == unstruct_grid::DONTKNOW)
            typeFlag = unstruct_grid::SCALAR;
    }
    else if (strcmp(DataObj->getType(), "USTVDT") == 0)
    {
        data[0].resize(1);
        data[0][0] = (DataObj);
        if (typeFlag == unstruct_grid::DONTKNOW)
            typeFlag = unstruct_grid::VECTOR;
    }
    else if (strcmp(DataObj->getType(), "POINTS") == 0)
    {
        data[0].resize(1);
        data[0][0] = (DataObj);
        if (typeFlag == unstruct_grid::DONTKNOW)
            typeFlag = unstruct_grid::POINT;
    }
    else
    {
        sendError("Only scalar or vector unstructured data, points or sets thereof are supported");
        return FAIL;
    }

    coDoUniformGrid **destGrids = NULL;
    const coDistributedObject *refGrid = Reference_Grid_In_Port->getCurrentObject();
    if (refGrid)
    {
        if (TimeSteps)
        {
            destGrids = new coDoUniformGrid *[num_set_ele];
        }
        else
        {
            destGrids = new coDoUniformGrid *[1];
        }

        if (!strcmp(refGrid->getType(), "SETELE"))
        {
            coDoSet *set = (coDoSet *)refGrid;
            int refgrid_num_set_ele;
            const coDistributedObject *const *refGridTimeSteps = set->getAllElements(&refgrid_num_set_ele);
            if (TimeSteps)
            {
                if (refgrid_num_set_ele != num_set_ele)
                {
                    sendError("Number of time steps in reference grid does not match data set");
                    return FAIL;
                }
                for (int i = 0; i < num_set_ele; i++)
                {
                    if (strcmp(refGridTimeSteps[i]->getType(), "UNIGRD"))
                    {
                        sendError("Reference grid must be a uniform grid or a set thereof");
                        return FAIL;
                    }
                    coDoUniformGrid *ugr = (coDoUniformGrid *)refGridTimeSteps[i];
                    destGrids[i] = ugr;
                }
            }
        }
        else
        {
            if (strcmp(refGrid->getType(), "UNIGRD"))
            {
                sendError("Reference grid must be a uniform grid or a set thereof");
                return FAIL;
            }

            coDoUniformGrid *ugr = (coDoUniformGrid *)refGrid;
            if (TimeSteps)
            {
                for (int i = 0; i < num_set_ele; i++)
                {
                    destGrids[i] = ugr;
                }
            }
            else
            {
                destGrids[0] = ugr;
            }
        }
    }

    if (Diagnose(grids, data, typeFlag, isStrGrid) < 0)
    {
        sendError("Grid and data are not compatible or an undefined problem occurred");
        return FAIL;
    }
    // check struncture of grids, sdata and vdata
    // Diagnose

    // check dimension of grid and data
    /*
      int numElems, numIndices, numCoords, numData;
      ((coDoUnstructuredGrid *)GridObj)->getGridSize(&numElems, &numIndices, &numCoords);
      numData = ((coDoFloat*)DataObj)->getNumPoints();
      if (numData != numCoords)
      {
      if (numData == numElems)
      {

      sendError("Sample supports only vertex based data - you seem to have cell based data");
      return FAIL;
      }
      else
      {
      char str[500];
      sprintf (str, "Dimension of data doesn't match dimension of grid - found %d coordinates and %d data", numCoords, numData);
      sendError(str);
      return FAIL;
      }
      }
    */

    // now we create an object for the output port: get the name and make the Obj
    const char *Grid_outObjName = Grid_Out_Port->getObjName();
    const char *Data_outObjName = Data_Out_Port->getObjName();
    char time_grid_name[64];
    char time_data_name[64];

    strcpy(time_grid_name, Grid_outObjName);
    strcpy(time_data_name, Data_outObjName);

    coDistributedObject **usg = new coDistributedObject *[grids.size() + 1];
    usg[grids.size()] = 0;

    coDistributedObject **str = new coDistributedObject *[grids.size() + 1];
    str[grids.size()] = 0;
    int strelem;
    for (strelem = 0; strelem < grids.size(); ++strelem)
    {
        str[strelem] = NULL;
    }

    float gmin[3] = { FLT_MAX, FLT_MAX, FLT_MAX },
          gmax[3] = { -FLT_MAX, -FLT_MAX, -FLT_MAX };
    if (!destGrids && p_bounding_box->getValue() == 1) // automatic globally
    {
        for (int time = 0; time < grids.size(); time++)
        {
            unstruct_grid *calc_grid = new unstruct_grid(grids[time],
                                                         typeFlag, isStrGrid);
            calc_grid->automaticBoundBox();
            const float *min, *max;
            calc_grid->getMinMax(min, max);
            for (int i = 0; i < 3; i++)
            {
                if (min[i] < gmin[i])
                    gmin[i] = min[i];
                if (max[i] > gmax[i])
                    gmax[i] = max[i];
            }
            delete calc_grid;
        }
    }

    for (int time = 0; time < grids.size(); time++)
    {
        if (TimeSteps)
        {
            sprintf(time_grid_name, "%s_%d", Grid_outObjName, time);
            sprintf(time_data_name, "%s_%d", Data_outObjName, time);
        }
        //        unstruct_grid *calc_grid=new unstruct_grid((coDoUnstructuredGrid*)GridObj);
        //int size = grids[time].size ();
        //@@@        int num_compressed = grids[time].num_compressed();
        unstruct_grid *calc_grid = new unstruct_grid(grids[time], typeFlag, isStrGrid);
        if (destGrids)
        {
            float min[3], max[3];
            destGrids[time]->getMinMax(&min[0], &max[0],
                                       &min[1], &max[1],
                                       &min[2], &max[2]);
            p_P1bound_manual->setValue(min[0], min[1], min[2]);
            p_P2bound_manual->setValue(max[0], max[1], max[2]);
            calc_grid->manualBoundBox(min[0], min[1], min[2],
                                      max[0], max[1], max[2]);

            destGrids[time]->getGridSize(&x_value, &y_value, &z_value);
        }
        else if (p_bounding_box->getValue() == 0) // automatic per timestep
        {
            calc_grid->automaticBoundBox();
            const float *min, *max;
            calc_grid->getMinMax(min, max);
            p_P1bound_manual->setValue(min[0], min[1], min[2]);
            p_P2bound_manual->setValue(max[0], max[1], max[2]);
        }
        else if (p_bounding_box->getValue() == 1) // automatic globally
        {
            calc_grid->manualBoundBox(gmin[0], gmin[1], gmin[2],
                                      gmax[0], gmax[1], gmax[2]);
        }
        else if (p_bounding_box->getValue() == 2) // manual
        {
            calc_grid->manualBoundBox(p_P1bound_manual->getValue(0),
                                      p_P1bound_manual->getValue(1),
                                      p_P1bound_manual->getValue(2),
                                      p_P2bound_manual->getValue(0),
                                      p_P2bound_manual->getValue(1),
                                      p_P2bound_manual->getValue(2));
        }
        const coDistributedObject **ndata = NULL;
        if (data.size() > time && data[time].size() > 0)
            ndata = &data[time][0];

        calc_grid->set_value(nan_flag, fill);

        // create data on strcutured grid
        if (grids[time].size() <= 0)
        {
            x_value = y_value = z_value = 1;
        }

        if ((typeFlag == unstruct_grid::SCALAR || typeFlag == unstruct_grid::VECTOR) && isStrGrid)
        {
            calc_grid->sample_structured(ndata,
                                         time_grid_name, &usg[time],
                                         time_data_name, &str[time], x_value, y_value, z_value);
        }
        else if (typeFlag == unstruct_grid::POINT)
        {
            calc_grid->sample_points(ndata,
                                     time_grid_name, &usg[time],
                                     time_data_name, &str[time], x_value, y_value, z_value,
                                     p_pointSampling->getValue());
        }
        else
        {
            switch (p_algorithm->getValue())
            {
            case SAMPLE_ACCURATE:
                // sl: this algorithm (the "old" one)
                //     is not as exact as it promises.
                //     The problem is that internally it calculates
                //     the indices around the element nodes approximating
                //     by default... As a result of this, strange
                //     effects appear sometimes near the borders.
                //     For this reason, and because it is very slow
                //     (that is why it is not worth the effort correcting
                //     the inaccuracies near the borders),
                //     the other new algorithms are recommended,
                //     especially SAMPLE_NO_HOLES_BETTER.
                calc_grid->sample_accu(ndata, /*&sdata[time][0] */
                                       time_grid_name, &usg[time],
                                       time_data_name, &str[time], x_value, y_value, z_value, eps);
                break;
            case SAMPLE_HOLES:
                calc_grid->sample_holes(ndata,
                                        time_grid_name, &usg[time], time_data_name, &str[time], x_value, y_value, z_value);
                break;
            case SAMPLE_NO_HOLES:
                calc_grid->sample_no_holes(ndata,
                                           time_grid_name, &usg[time],
                                           time_data_name, &str[time], x_value, y_value, z_value, 0);
                break;
            case SAMPLE_NO_HOLES_BETTER:
                calc_grid->sample_no_holes(ndata,
                                           time_grid_name, &usg[time],
                                           time_data_name, &str[time], x_value, y_value, z_value, 1);
                break;
            }
        }

        // attach the name of the input data object to the output grid object
        if ((typeFlag == unstruct_grid::SCALAR || typeFlag == unstruct_grid::VECTOR) && isStrGrid)
        {
            const char **names, **values;
            int n = grids[time][0]->getAllAttributes(&names, &values);
            for (int i = 0; i < n; i++)
            {
                if (strcmp(names[i], "Transformation") != 0)
                {
                    usg[time]->addAttribute(names[i], values[i]);
                }
            }
        }
        else
        {
            usg[time]->copyAllAttributes(grids[time][0]);
        }
        if (ndata)
        {
            usg[time]->addAttribute("DataObjectName", (*ndata)->getName());

            str[time]->copyAllAttributes((*ndata) /*sdata[time][0] */);
        }

        delete calc_grid;
    }

    // tell the output port that this is his object
    if (TimeSteps == 0)
    {
        Grid_Out_Port->setCurrentObject(usg[0]);
        Data_Out_Port->setCurrentObject(str[0]);
    }
    else
    {
        coDoSet *gridOutTime = new coDoSet(Grid_outObjName, usg);
        sprintf(time_grid_name, "1 %d", (int)grids.size());
        gridOutTime->addAttribute("TIMESTEP", time_grid_name);
        Grid_Out_Port->setCurrentObject(gridOutTime);
        //      if(typeFlag == unstruct_grid::SCALAR){
        coDoSet *dataOutTime = new coDoSet(Data_outObjName, str);
        dataOutTime->addAttribute("TIMESTEP", time_grid_name);
        Data_Out_Port->setCurrentObject(dataOutTime);
        //      }
    }

    // Add INTERACTOR attribute to the grid
    coFeedback feedback("Sample");
    feedback.addPara(iSizeParam);
    feedback.addPara(jSizeParam);
    feedback.addPara(kSizeParam);
    feedback.addPara(p_P1bound_manual);
    feedback.addPara(p_P2bound_manual);

    coDistributedObject *obj = Grid_Out_Port->getCurrentObject();
    if (obj)
        feedback.apply(obj);

    return SUCCESS;
}
Esempio n. 7
0
void TestLabel(WinEDA_DrawPanel * panel, wxDC * DC,
               ObjetNetListStruct * NetItemRef, ObjetNetListStruct * StartNet)
/***********************************************************************/
/* Routine controlant qu'un sheetLabel est bien connecte a un Glabel de la
sous-feuille correspondante
*/
{
    ObjetNetListStruct * NetItemTst, * Lim;
    int erc = 1;

    /* Analyse de la table des connexions : */
    Lim = g_TabObjNet + g_NbrObjNet;

    NetItemTst = StartNet;

    /* Examen de la liste des Labels connectees a NetItemRef */
    for ( ; ; NetItemTst ++ )
    {
        if( NetItemTst == NetItemRef ) continue;

        /* Est - on toujours dans le meme net ? */
        if( ( NetItemTst ==  Lim ) ||
                ( NetItemRef->m_NetCode != NetItemTst->m_NetCode ) )
        {   /* Fin de netcode trouve */
            if( erc )
            {   /* GLabel ou SheetLabel orphelin */
                Diagnose(panel, DC, NetItemRef, NULL, -1, WAR);
            }
            return;
        }

        if( (NetItemRef->m_Type == NET_GLOBLABEL) ||
                (NetItemRef->m_Type == NET_GLOBBUSLABELMEMBER) )
        {
            switch ( NetItemTst->m_Type )
            {
            case NET_SEGMENT:
            case NET_BUS:
            case NET_JONCTION:
            case NET_LABEL:
            case NET_GLOBLABEL:
            case NET_BUSLABELMEMBER:
            case NET_GLOBBUSLABELMEMBER:
            case NET_PINLABEL:
            case NET_NOCONNECT:
            case NET_PIN:
                break;

            case NET_SHEETBUSLABELMEMBER:
            case NET_SHEETLABEL:
                /* Tst si le GLabel est bien dans la bonne sousfeuille */
                if( NetItemRef->m_SheetNumber == NetItemTst->m_NumInclude )
                {
                    erc = 0;
                }
                break;
            }
        }

        else
        {
            switch ( NetItemTst->m_Type )
            {
            case NET_SEGMENT:
            case NET_BUS:
            case NET_JONCTION:
            case NET_LABEL:
            case NET_BUSLABELMEMBER:
            case NET_SHEETBUSLABELMEMBER:
            case NET_SHEETLABEL:
            case NET_PINLABEL:
            case NET_NOCONNECT:
            case NET_PIN:
                break;

            case NET_GLOBLABEL:
            case NET_GLOBBUSLABELMEMBER:
                /* Tst si le GLabel est bien dans la bonne sous-feuille */
                if( NetItemTst->m_SheetNumber == NetItemRef->m_NumInclude )
                {
                    erc = 0;
                }
                break;
            }
        }
    }
}
Esempio n. 8
0
static void TestOthersItems(WinEDA_DrawPanel * panel, wxDC * DC,
                            ObjetNetListStruct *  NetItemRef,
                            ObjetNetListStruct *  netstart,
                            int * NetNbItems, int * MinConnexion)
/********************************************************************/
/* Routine testant les conflits electriques entre
	NetItemRef
	et les autres items du meme net
*/
{
    ObjetNetListStruct * NetItemTst, * Lim;
    int ref_elect_type, jj, erc = OK, local_minconn;

    /* Analyse de la table des connexions : */
    Lim = g_TabObjNet + g_NbrObjNet; // pointe la fin de la liste
    ref_elect_type = NetItemRef->m_ElectricalType;

    NetItemTst = netstart;
    local_minconn = NOC;

    /* Examen de la liste des Pins connectees a NetItemRef */
    for ( ; ; NetItemTst ++ )
    {
        if ( NetItemRef == NetItemTst ) continue;

        /* Est - on toujours dans le meme net ? */
        if( (NetItemTst >= Lim) ||  	// fin de liste (donc fin de net)
                (NetItemRef->m_NetCode != NetItemTst->m_NetCode) )  // fin de net
        {   /* Fin de netcode trouve: Tst connexion minimum */
            if( (*MinConnexion < NET_NC ) &&
                    (local_minconn < NET_NC ) ) /* pin non connectée ou non pilotee */
            {
                Diagnose(panel, DC, NetItemRef, NULL, local_minconn, WAR);
                * MinConnexion = DRV;	// inhibition autres messages de ce type pour ce net
            }
            return;
        }

        switch ( NetItemTst->m_Type )
        {
        case NET_SEGMENT:
        case NET_BUS:
        case NET_JONCTION:
        case NET_LABEL:
        case NET_GLOBLABEL:
        case NET_BUSLABELMEMBER:
        case NET_GLOBBUSLABELMEMBER:
        case NET_SHEETBUSLABELMEMBER:
        case NET_SHEETLABEL:
        case NET_PINLABEL:
            break;

        case NET_NOCONNECT:
            local_minconn = MAX( NET_NC, local_minconn);
            break;

        case NET_PIN:
            jj = NetItemTst->m_ElectricalType;
            local_minconn = MAX( MinimalReq[ref_elect_type][jj], local_minconn );

            if ( NetItemTst <= NetItemRef ) break;
            *NetNbItems += 1;
            if( erc == OK )		// 1 marqueur par pin maxi
            {
                erc = DiagErc[ref_elect_type][jj];
                if (erc != OK )
                {
                    if( NetItemTst->m_FlagOfConnection == 0 )
                    {
                        Diagnose(panel, DC, NetItemRef, NetItemTst, 0, erc);
                        NetItemTst->m_FlagOfConnection = (IsConnectType) 1;
                    }
                }
            }
            break;
        }
    }
}
Esempio n. 9
0
void WinEDA_ErcFrame::TestErc(wxCommandEvent& event)
/**************************************************/
{
    ObjetNetListStruct * NetItemRef, * OldItem, * StartNet, * Lim;
    int NetNbItems, MinConn;

    if ( ! DiagErcTableInit )
    {
        memcpy(DiagErc, DefaultDiagErc, sizeof (DefaultDiagErc));
        DiagErcTableInit = TRUE;
    }

    WriteFichierERC = m_WriteResultOpt->GetValue();

    if( CheckAnnotate(m_Parent, 0) )
    {
        DisplayError(this, _("Annotation Required!") );
        return;
    }

    /* Effacement des anciens marqueurs DRC */
    DelERCMarkers(event);

    wxClientDC dc(m_Parent->DrawPanel);

    m_Parent->DrawPanel->PrepareGraphicContext(&dc);

    g_EESchemaVar.NbErrorErc = 0;
    g_EESchemaVar.NbWarningErc = 0;

    SchematicCleanUp(&dc);

    BuildNetList(m_Parent, ScreenSch);

    /* Analyse de la table des connexions : */
    Lim = g_TabObjNet + g_NbrObjNet;

    /* Reset du flag m_FlagOfConnection, utilise par la suite */
    for (NetItemRef = g_TabObjNet; NetItemRef < Lim; NetItemRef ++ )
        NetItemRef->m_FlagOfConnection = (IsConnectType) 0;

    NetNbItems = 0;
    MinConn = NOC;
    StartNet = OldItem = NetItemRef = g_TabObjNet;
    for ( ; NetItemRef < Lim; NetItemRef ++ )
    {
        /* Tst changement de net */
        if( OldItem->m_NetCode != NetItemRef->m_NetCode)
        {
            MinConn = NOC;
            NetNbItems = 0;
            StartNet = NetItemRef;
        }

        switch ( NetItemRef->m_Type )
        {
        case NET_SEGMENT:
        case NET_BUS:
        case NET_JONCTION:
        case NET_LABEL:
        case NET_BUSLABELMEMBER:
        case NET_PINLABEL:
            break;

        case NET_GLOBLABEL:
        case NET_GLOBBUSLABELMEMBER:
        case NET_SHEETLABEL:
        case NET_SHEETBUSLABELMEMBER:
            TestLabel(m_Parent->DrawPanel, &dc, NetItemRef, StartNet);
            break;

        case NET_NOCONNECT:
            MinConn = NET_NC;
            if( NetNbItems != 0 )
                Diagnose(m_Parent->DrawPanel, &dc, NetItemRef, NULL, MinConn, UNC);
            break;

        case NET_PIN:
            TestOthersItems(m_Parent->DrawPanel, &dc,
                            NetItemRef, StartNet, &NetNbItems , &MinConn);
            break;
        }
        OldItem = NetItemRef;
    }

    FreeTabNetList(g_TabObjNet, g_NbrObjNet );

    wxString num;
    num.Printf(wxT("%d"), g_EESchemaVar.NbErrorErc);
    m_TotalErrCount->SetLabel(num);

    num.Printf(wxT("%d"), g_EESchemaVar.NbErrorErc-g_EESchemaVar.NbWarningErc);
    m_LastErrCount->SetLabel(num);

    num.Printf(wxT("%d"), g_EESchemaVar.NbWarningErc);
    m_LastWarningCount->SetLabel(num);

    /* Generation ouverture fichier diag */
    if( WriteFichierERC == TRUE )
    {
        wxString ErcFullFileName;
        ErcFullFileName = ScreenSch->m_FileName;
        ChangeFileNameExt(ErcFullFileName, wxT(".erc"));
        ErcFullFileName = EDA_FileSelector(_("ERC file:"),
                                           wxEmptyString,					/* Chemin par defaut */
                                           ErcFullFileName,	/* nom fichier par defaut */
                                           wxT(".erc"),				/* extension par defaut */
                                           wxT("*.erc"),			/* Masque d'affichage */
                                           this,
                                           wxSAVE,
                                           TRUE
                                          );
        if ( ErcFullFileName.IsEmpty()) return;

        if ( WriteDiagnosticERC(ErcFullFileName) )
        {
            Close(TRUE);
            wxString editorname = GetEditorName();
            AddDelimiterString(ErcFullFileName);
            ExecuteFile(this, editorname, ErcFullFileName);
        }
    }
}
Esempio n. 10
0
void DIALOG_ERC::TestErc( wxArrayString* aMessagesList )
{
    wxFileName fn;

    if( !DiagErcTableInit )
    {
        memcpy( DiagErc, DefaultDiagErc, sizeof(DefaultDiagErc) );
        DiagErcTableInit = true;
    }

    m_writeErcFile = m_WriteResultOpt->GetValue();

    /* Build the whole sheet list in hierarchy (sheet, not screen) */
    SCH_SHEET_LIST sheets;
    sheets.AnnotatePowerSymbols();

    if( m_parent->CheckAnnotate( aMessagesList, false ) )
    {
        if( aMessagesList )
        {
            wxString msg = _( "Annotation required!" );
            msg += wxT( "\n" );
            aMessagesList->Add( msg );
        }

        return;
    }

    SCH_SCREENS screens;

    // Erase all previous DRC markers.
    screens.DeleteAllMarkers( MARK_ERC );

    for( SCH_SCREEN* screen = screens.GetFirst(); screen != NULL; screen = screens.GetNext() )
    {
        /* Ff wire list has changed, delete Undo Redo list to avoid pointers on deleted
         * data problems.
         */
        if( screen->SchematicCleanUp( NULL ) )
            screen->ClearUndoRedoList();
    }

    /* Test duplicate sheet names inside a given sheet, one cannot have sheets with
     * duplicate names (file names can be duplicated).
     */
    TestDuplicateSheetNames( true );

    NETLIST_OBJECT_LIST* objectsConnectedList = m_parent->BuildNetListBase();

    // Reset the connection type indicator
    objectsConnectedList->ResetConnectionsType();

    unsigned lastNet;
    unsigned nextNet = lastNet = 0;
    int NetNbItems = 0;
    int MinConn    = NOC;

    for( unsigned net = 0; net < objectsConnectedList->size(); net++ )
    {
        if( objectsConnectedList->GetItemNet( lastNet ) !=
            objectsConnectedList->GetItemNet( net ) )
        {
            // New net found:
            MinConn    = NOC;
            NetNbItems = 0;
            nextNet   = net;
        }

        switch( objectsConnectedList->GetItemType( net ) )
        {
        // These items do not create erc problems
        case NET_ITEM_UNSPECIFIED:
        case NET_SEGMENT:
        case NET_BUS:
        case NET_JUNCTION:
        case NET_LABEL:
        case NET_BUSLABELMEMBER:
        case NET_PINLABEL:
        case NET_GLOBLABEL:
        case NET_GLOBBUSLABELMEMBER:
            break;

        case NET_HIERLABEL:
        case NET_HIERBUSLABELMEMBER:
        case NET_SHEETLABEL:
        case NET_SHEETBUSLABELMEMBER:

            // ERC problems when pin sheets do not match hierarchical labels.
            // Each pin sheet must match a hierarchical label
            // Each hierarchical label must match a pin sheet
            TestLabel( objectsConnectedList, net, nextNet );
            break;

        case NET_NOCONNECT:

            // ERC problems when a noconnect symbol is connected to more than one pin.
            MinConn = NET_NC;

            if( NetNbItems != 0 )
                Diagnose( objectsConnectedList->GetItem( net ), NULL, MinConn, UNC );

            break;

        case NET_PIN:

            // Look for ERC problems between pins:
            TestOthersItems( objectsConnectedList, net, nextNet, &NetNbItems, &MinConn );
            break;
        }

        lastNet = net;
    }

    // Displays global results:
    wxString num;
    int markers = screens.GetMarkerCount();
    int warnings = screens.GetMarkerCount( WAR );

    num.Printf( wxT( "%d" ), markers );
    m_TotalErrCount->SetLabel( num );

    num.Printf( wxT( "%d" ), markers - warnings );
    m_LastErrCount->SetLabel( num );

    num.Printf( wxT( "%d" ), warnings );
    m_LastWarningCount->SetLabel( num );

    // Display diags:
    DisplayERC_MarkersList();

    // Display new markers:
    m_parent->GetCanvas()->Refresh();

    if( m_writeErcFile )
    {
        fn = g_RootSheet->GetScreen()->GetFileName();
        fn.SetExt( wxT( "erc" ) );

        wxFileDialog dlg( this, _( "ERC File" ), fn.GetPath(), fn.GetFullName(),
                          _( "Electronic rule check file (.erc)|*.erc" ),
                          wxFD_SAVE | wxFD_OVERWRITE_PROMPT );

        if( dlg.ShowModal() == wxID_CANCEL )
            return;

        if( WriteDiagnosticERC( dlg.GetPath() ) )
        {
            Close( true );
            ExecuteFile( this, wxGetApp().GetEditorName(), QuoteFullPath( fn ) );
        }
    }
}