95 kiapi::board::commands::BoardDesignRulesResponse* aOut, wxString* aError =
nullptr )
97 kiapi::board::commands::GetBoardDesignRules request;
98 *request.mutable_board() = aDocument;
100 kiapi::common::ApiResponse response;
110 if( response.status().status() != kiapi::common::AS_OK )
113 *aError = response.status().error_message();
118 if( !response.message().UnpackTo( aOut ) )
121 *aError = wxS(
"Failed to unpack BoardDesignRulesResponse" );
131 kiapi::board::commands::CustomRulesResponse* aOut, wxString* aError =
nullptr )
133 kiapi::board::commands::GetCustomDesignRules request;
134 *request.mutable_board() = aDocument;
136 kiapi::common::ApiResponse response;
146 if( response.status().status() != kiapi::common::AS_OK )
149 *aError = response.status().error_message();
154 if( !response.message().UnpackTo( aOut ) )
157 *aError = wxS(
"Failed to unpack CustomRulesResponse" );
179 BOOST_REQUIRE_MESSAGE( Start(), LastError() );
181 kiapi::common::types::DocumentSpecifier document;
183 wxFileName boardPath( testDataDir, wxS(
"api_kitchen_sink.kicad_pcb" ) );
185 BOOST_REQUIRE_MESSAGE( Client().OpenDocument( boardPath.GetFullPath(), &document ),
186 "OpenDocument failed: " + Client().LastError() );
188 BOOST_REQUIRE( document.type() == kiapi::common::types::DOCTYPE_PCB );
189 BOOST_REQUIRE( boardPath.GetFullName().Matches( document.board_filename() ) );
191 int footprintCount = 0;
193 BOOST_REQUIRE_MESSAGE( Client().GetItemsCount( document, kiapi::common::types::KOT_PCB_FOOTPRINT, &footprintCount ),
194 "GetItems failed: " + Client().LastError() );
196 BOOST_CHECK_GT( footprintCount, 0 );
202 BOOST_REQUIRE_MESSAGE( Start(), LastError() );
205 wxFileName boardPathA( testDataDir, wxS(
"api_kitchen_sink.kicad_pcb" ) );
206 wxFileName boardPathB( testDataDir, wxS(
"padstacks.kicad_pcb" ) );
208 kiapi::common::types::DocumentSpecifier documentA;
210 BOOST_REQUIRE_MESSAGE( Client().OpenDocument( boardPathA.GetFullPath(), &documentA ),
211 "OpenDocument for first board failed: " + Client().LastError() );
215 BOOST_REQUIRE_MESSAGE( Client().GetFirstFootprint( documentA, &footprintA ),
216 "GetFirstFootprint for first board failed: " + Client().LastError() );
218 kiapi::common::types::DocumentSpecifier documentB;
220 BOOST_REQUIRE_MESSAGE( Client().OpenDocument( boardPathB.GetFullPath(), &documentB ),
221 "OpenDocument for second board failed: " + Client().LastError() );
225 BOOST_REQUIRE_MESSAGE( Client().GetFirstFootprint( documentB, &footprintB ),
226 "GetFirstFootprint for second board failed: " + Client().LastError() );
228 BOOST_CHECK_NE( footprintA.
Similarity( footprintB ), 1.0 );
230 kiapi::common::ApiStatusCode closeStatus = kiapi::common::AS_UNKNOWN;
232 BOOST_REQUIRE_MESSAGE( Client().CloseDocument( &documentB, &closeStatus ),
233 "CloseDocument failed: " + Client().LastError() );
236 BOOST_REQUIRE_MESSAGE( Client().CloseDocument(
nullptr, &closeStatus ),
237 "CloseDocument after already closed failed: " + Client().LastError() );
244 BOOST_REQUIRE_MESSAGE( Start(), LastError() );
246 kiapi::common::types::DocumentSpecifier document;
249 BOOST_REQUIRE_MESSAGE( Client().OpenDocument( boardPath.GetFullPath(), &document ),
250 "OpenDocument failed: " + Client().LastError() );
252 kiapi::board::commands::BoardDesignRulesResponse rulesResponse;
256 "GetBoardDesignRules failed: " + error );
258 BOOST_CHECK_GE( rulesResponse.rules().constraints().min_clearance().value_nm(), 0 );
259 BOOST_CHECK_GE( rulesResponse.rules().constraints().min_track_width().value_nm(), 0 );
260 BOOST_CHECK( rulesResponse.custom_rules_status() == kiapi::board::commands::CRS_VALID );
266 BOOST_REQUIRE_MESSAGE( Start(), LastError() );
271 BOOST_REQUIRE_MESSAGE( fixtureCopy.
Create( ©Error ), copyError );
273 kiapi::common::types::DocumentSpecifier document;
275 BOOST_REQUIRE_MESSAGE( Client().OpenDocument( fixtureCopy.
BoardPath(), &document ),
276 "OpenDocument failed: " + Client().LastError() );
278 kiapi::board::commands::BoardDesignRulesResponse getResponse;
281 "Initial GetBoardDesignRules failed: " + copyError );
283 int newWidth = getResponse.rules().constraints().min_track_width().value_nm() + 1000;
285 kiapi::board::commands::SetBoardDesignRules setRequest;
286 *setRequest.mutable_board() = document;
287 *setRequest.mutable_rules()->mutable_constraints() = getResponse.rules().constraints();
288 setRequest.mutable_rules()->mutable_constraints()->mutable_min_track_width()->set_value_nm( newWidth );
290 kiapi::common::ApiResponse setApiResponse;
292 BOOST_REQUIRE_MESSAGE( Client().
SendCommand( setRequest, &setApiResponse ),
293 "SetBoardDesignRules failed to send: " + Client().LastError() );
294 BOOST_REQUIRE( setApiResponse.status().status() == kiapi::common::AS_OK );
296 kiapi::board::commands::BoardDesignRulesResponse setResponse;
297 BOOST_REQUIRE( setApiResponse.message().UnpackTo( &setResponse ) );
299 BOOST_CHECK_EQUAL( setResponse.rules().constraints().min_track_width().value_nm(), newWidth );
301 kiapi::board::commands::BoardDesignRulesResponse verifyResponse;
304 "Verification GetBoardDesignRules failed: " + copyError );
306 BOOST_CHECK_EQUAL( verifyResponse.rules().constraints().min_track_width().value_nm(), newWidth );
312 BOOST_REQUIRE_MESSAGE( Start(), LastError() );
317 BOOST_REQUIRE_MESSAGE( fixtureCopy.
Create( ©Error ), copyError );
319 kiapi::common::types::DocumentSpecifier document;
321 BOOST_REQUIRE_MESSAGE( Client().OpenDocument( fixtureCopy.
BoardPath(), &document ),
322 "OpenDocument failed: " + Client().LastError() );
324 kiapi::board::commands::BoardDesignRulesResponse getResponse;
327 "Initial GetBoardDesignRules failed: " + copyError );
329 kiapi::board::commands::SetBoardDesignRules setRequest;
330 *setRequest.mutable_board() = document;
331 *setRequest.mutable_rules()->mutable_constraints() = getResponse.rules().constraints();
332 setRequest.mutable_rules()->mutable_constraints()->mutable_min_track_width()->set_value_nm( 1000000000 );
334 kiapi::common::ApiResponse response;
336 BOOST_REQUIRE_MESSAGE( Client().
SendCommand( setRequest, &response ),
337 "SetBoardDesignRules failed to send: " + Client().LastError() );
339 BOOST_CHECK( response.status().status() == kiapi::common::AS_BAD_REQUEST );
340 BOOST_CHECK( !response.status().error_message().empty() );
346 BOOST_REQUIRE_MESSAGE( Start(), LastError() );
351 BOOST_REQUIRE_MESSAGE( fixtureCopy.
Create( ©Error ), copyError );
353 kiapi::common::types::DocumentSpecifier document;
355 BOOST_REQUIRE_MESSAGE( Client().OpenDocument( fixtureCopy.
BoardPath(), &document ),
356 "OpenDocument failed: " + Client().LastError() );
358 kiapi::board::commands::BoardDesignRulesResponse getResponse;
360 "Initial GetBoardDesignRules failed: " + copyError );
362 auto applySeverityAndVerify = [&]( kiapi::common::types::RuleSeverity aSeverity )
364 kiapi::board::commands::SetBoardDesignRules setRequest;
365 *setRequest.mutable_board() = document;
367 kiapi::board::DrcSeveritySetting* setting = setRequest.mutable_rules()->add_severities();
368 setting->set_rule_type( kiapi::board::DrcErrorType::DRCET_UNCONNECTED_ITEMS );
369 setting->set_severity( aSeverity );
371 kiapi::common::ApiResponse setApiResponse;
372 BOOST_REQUIRE_MESSAGE( Client().
SendCommand( setRequest, &setApiResponse ),
373 "SetBoardDesignRules failed to send: " + Client().LastError() );
374 BOOST_REQUIRE( setApiResponse.status().status() == kiapi::common::AS_OK );
376 kiapi::board::commands::BoardDesignRulesResponse verifyResponse;
378 "Verification GetBoardDesignRules failed: " + copyError );
382 for(
const kiapi::board::DrcSeveritySetting& severity : verifyResponse.rules().severities() )
384 if( severity.rule_type() == kiapi::board::DrcErrorType::DRCET_UNCONNECTED_ITEMS )
387 BOOST_CHECK( severity.severity() == aSeverity );
392 BOOST_CHECK( found );
395 applySeverityAndVerify( kiapi::common::types::RS_IGNORE );
396 applySeverityAndVerify( kiapi::common::types::RS_ERROR );
402 BOOST_REQUIRE_MESSAGE( Start(), LastError() );
404 kiapi::common::types::DocumentSpecifier document;
407 BOOST_REQUIRE_MESSAGE( Client().OpenDocument( boardPath.GetFullPath(), &document ),
408 "OpenDocument failed: " + Client().LastError() );
410 kiapi::board::commands::CustomRulesResponse response;
414 "GetCustomDesignRules failed: " + error );
416 BOOST_CHECK( response.status() == kiapi::board::commands::CRS_VALID );
417 BOOST_CHECK_GT( response.rules_size(), 0 );
419 bool foundFixtureRule =
false;
421 for(
const kiapi::board::CustomRule& rule : response.rules() )
423 if( rule.name() ==
"myrule" )
425 foundFixtureRule =
true;
433 BOOST_CHECK( foundFixtureRule );
439 BOOST_REQUIRE_MESSAGE( Start(), LastError() );
444 BOOST_REQUIRE_MESSAGE( fixtureCopy.
Create( ©Error ), copyError );
446 kiapi::common::types::DocumentSpecifier document;
448 BOOST_REQUIRE_MESSAGE( Client().OpenDocument( fixtureCopy.
BoardPath(), &document ),
449 "OpenDocument failed: " + Client().LastError() );
451 kiapi::board::commands::CustomRulesResponse response;
455 "GetCustomDesignRules failed: " + error );
457 BOOST_CHECK( response.status() == kiapi::board::commands::CRS_VALID );
458 BOOST_CHECK_GT( response.rules_size(), 0 );
460 kiapi::board::commands::SetCustomDesignRules setRequest;
461 *setRequest.mutable_board() = document;
463 setRequest.mutable_rules()->CopyFrom( response.rules() );
465 kiapi::board::CustomRule* rule = setRequest.add_rules();
466 rule->set_name(
"api_roundtrip_rule" );
467 rule->set_condition(
"A.NetClass == 'HV'" );
468 rule->set_layer_mode( kiapi::board::CRLM_OUTER );
469 rule->set_severity( kiapi::common::types::RS_WARNING );
471 kiapi::board::CustomRuleConstraint* annular = rule->add_constraints();
472 annular->set_type( kiapi::board::CRCT_TRACK_WIDTH );
473 annular->mutable_numeric()->set_min( 3000000 );
474 annular->mutable_numeric()->set_opt( 4000000 );
475 annular->mutable_numeric()->set_max( 5000000 );
477 kiapi::board::CustomRuleConstraint* disallow = rule->add_constraints();
478 disallow->set_type( kiapi::board::CRCT_DISALLOW );
479 disallow->mutable_disallow()->add_types( kiapi::board::CRDT_BLIND_VIAS );
481 kiapi::common::ApiResponse setApiResponse;
483 BOOST_REQUIRE_MESSAGE( Client().
SendCommand( setRequest, &setApiResponse ),
484 "SetCustomDesignRules failed to send: " + Client().LastError() );
485 BOOST_REQUIRE( setApiResponse.status().status() == kiapi::common::AS_OK );
487 kiapi::board::commands::CustomRulesResponse setResponse;
488 BOOST_REQUIRE( setApiResponse.message().UnpackTo( &setResponse ) );
490 int num_rules = setResponse.rules_size();
491 BOOST_CHECK( setResponse.status() == kiapi::board::commands::CRS_VALID );
493 BOOST_CHECK_EQUAL( setResponse.rules( num_rules - 1 ).name(),
"api_roundtrip_rule" );
BOOST_CHECK_EQUAL(result, "25.4")